I'm trying to assemble a multi-module project.

visual 2012.

I connect the header files like this:

module.h

source code: module.cpp main.cpp

// Вот здесь правильно? Так сделано в прекомпилированном заголовке. module.cpp [[ include "module.h" ]] module.h [[ // Вот такие включения идут нормально #include <windows.h> #include <string> #include <iostream> //Но есть библиотека mpir. //И там есть код extern "C" { int __gmp_printf (const char *, ...); } //Функция __gmp_printf определена в .lib файле. #pragma comment(lib,"mpir.lib") // Дальше её вызываю struct class_ { class_() { __gmp_printf("text"); } }; Лезут ошибки libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned __int64)" (?_invalid_parameter@@YAXPEBG00I_K@Z) уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned __int64)" (?_invoke_watson@@YAXPEBG00I_K@Z) уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: _call_reportfault уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: _get_invalid_parameter_handler уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: _initp_misc_invarg уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: _invalid_parameter уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: _invoke_watson уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: _set_invalid_parameter_handler уже определен в LIBCMTD.lib(invarg.obj) 1>libcmt.lib(invarg.obj) : error LNK2005: __pInvalidArgHandler уже определен в LIBCMTD.lib(invarg.obj) 1>LIBCMTD.lib(crt0init.obj) : warning LNK4098: библиотека по умолчанию "libcmt.lib" противоречит использованию других библиотек; используйте параметр /NODEFAULTLIB:library Пробовал включение .lib класть в module.cpp и main.cpp: ничего не помогает. class_ вынести в main.cpp тоже самое. ]] main.cpp [[ #include "module.h" class_ d; int main() { return 1; } ]] 
  • And tried not to connect #pragma comment(lib,"mpir.lib") ? Judging by the conclusion, it is already connected. - KoVadim
  • The function is inside .lib. without it, the "not allowed external character" goes. - manking

2 answers 2

It seems that the application is going to release, and the library is in debugging or vice versa. Each part pulls its own version of runtime and conflicts occur. It is necessary that the library and the application have the same configuration.

  • Here is the correct answer if you want to do it right. - mikelsv
  • Earned with release - the runtime library is multi-threaded. I tried these settings from the very beginning: ((apparently carelessly. Thank you. - manking

If you really want to make it work by any means that is /FORCE:MULTIPLE which you need to add to the linker options. / FORCE (Force File Output) .

  • one
    Compiles, but produces: Debug assertion Failed! expression: pHead-> nBlockUse == nBlockUse - manking
  • one
    This is already something with the compatibility of the program and the library. If you can, collect them in the same version of the studio with the same parameters. Then / FORCE: MULTIPLE is not needed. - mikelsv