想让一个动态链接库文件debug和release编译的时候生成不同的文件名用
#ifdef _DEBUG
#pragma comment(linker, "/out:test_d.dll")
#else
#pragma comment(linker, "/out:test.dll")
#endif
会产生出错信息:
warning LNK4070: /OUT:test_de.dll directive in .EXP differs from output filename "Debug/test.dll"; ignoring directive
debug编译的时候文件名仍然是原来的文件名,没有变化。如果在debug的setting-link-output file name里面改的话,必须要将test.def里面的LIBRARY也改为test_d.dll才行,否则会出相同的错。这样每次在debug和release之间切换的时候都要改test.def,很不方便。有什么别的办法吗?多谢!
#ifdef _DEBUG
#pragma comment(linker, "/out:test_d.dll")
#else
#pragma comment(linker, "/out:test.dll")
#endif
会产生出错信息:
warning LNK4070: /OUT:test_de.dll directive in .EXP differs from output filename "Debug/test.dll"; ignoring directive
debug编译的时候文件名仍然是原来的文件名,没有变化。如果在debug的setting-link-output file name里面改的话,必须要将test.def里面的LIBRARY也改为test_d.dll才行,否则会出相同的错。这样每次在debug和release之间切换的时候都要改test.def,很不方便。有什么别的办法吗?多谢!
在settings里面修改也行。但是还是有问题。
用第一种方法,只生成了test_d.dll,没有生成test_d.lib,这样只能显式调用,但是我想隐式调用。用修改settings的方法,能生成test_d.dll和test_d.lib,但是test_d.lib里面动态库的internal name仍然是test.dll,所以必须修改test.def里面的LIBRARY,从test.dll改为test_d.dll才行,否则运行的时候报告找不到“test.dll”。这样虽然能用,但是debug编译的时候要把test.def里面的LIBRARY改为test_d.dll,release编译的时候,又要把LIBRARY,改回test.dll,很麻烦,而且容易忘记。不知道能不能在程序里面自动修改LIBRARY?
如果不改test.def里面的LIBRARY,虽然能生成test_d.dll和test_d.lib,但是运行的时候仍然会找test.dll,因为internal name是test.dll。
主要问题是不知道怎么自动修改internal name,test.def里面不支持#ifdef _DEBUG这样的东东。
#ifdef _DEBUG
#pragma comment(linker, "/out:debug/test_d.dll")
#else
#pragma comment(linker, "/out:release/test.dll")
#endif
就可以了
#ifdef _DEBUG
#pragma comment(linker, "/out:debug/test_d.dll")
#else
#pragma comment(linker, "/out:release/test.dll")
#endif
有问题,
LINK : fatal error LNK1181: cannot open input file "Debug/test_D.exp",不知道为什么。
不过没关系,不用用这个了。直接在settings里设置编译后的文件名称即可。总结一下,让一个动态链接库文件debug和release编译的时候生成不同的文件名的方法:
1、去掉DEF文件中的LIBRARY;
2、修改settings-link-output file name,改为希望的名字,比如debug的改为test_d.dll,release的不变。
1很重要,否则虽然生成了test_d.dll和test_d.lib,但是运行的时候会报告找不到动态链接库"test.dll",因为test_d.lib中使用的internal name是"test.dll",去掉DEF文件中的LIBRARY以后就没有这个问题了!