我有几个项目A到F,每个项目都依赖于静态库L。每个项目都是我的Visual Studio解决方案中的一个项目。
不幸的是,项目F需要构建静态库的风格略有不同(当前是通过在build选项中定义一个预处理程序指令以使用if / endif指令选择不同的代码段来实现的,因为特殊情况下的代码会添加其他内容) AE无关的依赖项。)
我目前通过制作第二个库项目“ L_withflag”来解决此问题,该项目包括所有相同的源文件,并且工作得很好。我想知道是否有一种更简单的方法,不需要使用相同的基础代码库维护两个单独的项目。
有没有一种方法可以使静态库项目L生成两个输出,一个输出带有标志集,一个不带标志(例如L.lib和L_withflag.lib),并允许每个项目指定它想要输入哪个库?
答案 0 :(得分:0)
Visual Studio使您可以为解决方案提供多种构建配置。默认情况下,对于C ++,您将获得Debug和Release配置,但是您可以通过以下方法添加其他配置
import javax.crypto.*;
import javax.crypto.spec.GCMParameterSpec;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.ArrayList;
import java.util.Scanner;
public class TestPasswordVault {
private static ArrayList<Password> passwordVault;
public Scanner keyboard = new Scanner(System.in);
public String website;
public String username;
private String password;
private static SecretKey key;
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException, InvalidKeyException, InvalidAlgorithmParameterException, NoSuchProviderException {
String test = "kittens";
SecureRandom random = SecureRandom.getInstanceStrong();
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(128, random);
SecretKey key = keyGen.generateKey();
byte[] iv = new byte[12];
random.nextBytes(iv);
System.out.println(test);
byte [] newTest = doEncrypt(test,iv,random,key);
System.out.println(newTest);
System.out.println(doDecrypt(newTest,iv,random,key));
}
public static byte [] doEncrypt(String password, byte [] iv, SecureRandom random, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, UnsupportedEncodingException {
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "SunJCE");
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
cipher.init(Cipher.ENCRYPT_MODE, key, spec);
byte [] encryptPassword = password.getBytes("UTF-8");
byte[] cipherText = cipher.doFinal(encryptPassword);
return cipherText;
}
public static String doDecrypt(byte [] encrypted, byte [] iv, SecureRandom random, SecretKey key)throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, UnsupportedEncodingException {
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "SunJCE");
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
cipher.init(Cipher.DECRYPT_MODE, key, spec);
byte[] plainText = cipher.doFinal(encrypted);
return new String(plainText);
}
}
选择“新建”时,可以从现有配置(调试,发布)中复制设置。因此,您可以创建配置“发行-选项A”,“发行-选项B”,然后编辑每个项目的项目设置以设置不同的预处理程序指令。
在项目设置中,您还可以设置不同的DLL名称和/或输出文件夹。