Errno and a linking problem (again...)
-
Hello, Still struggling with the linker. Many things have been solved, but still (at least) one left. So, I have mylib.lib, which is written in C and I'm using it in my console program, that uses also MFC. I have the source code of that lib, but I can't change it. I use makefile for compiling and linking. I have (among others) compile options /TP /MT, so it's C++ and multithreaded. With a linker option /NODEFAULTLIB:libc.lib, I avoid crashes with libcmt.lib. So I compile my selfmade files and then link the .obj files and .libs and I get error LNK2001: unresolved external symbol _errno. The place where I get this error from is in one file in mylib. I checked, that it includes header errno.h. If I remove linker option /NODEFAULTLIB:libc.lib, this error of _errno disappears, but I get lots of errors, because libc and libctm define same functions. Or if I make it single threaded, the problem is with _begingthreadex and _endthreadex. I don't understand. Why doesn't the linker realize errno? :confused: Could it be because of messing with C and C++? -Janetta
-
Hello, Still struggling with the linker. Many things have been solved, but still (at least) one left. So, I have mylib.lib, which is written in C and I'm using it in my console program, that uses also MFC. I have the source code of that lib, but I can't change it. I use makefile for compiling and linking. I have (among others) compile options /TP /MT, so it's C++ and multithreaded. With a linker option /NODEFAULTLIB:libc.lib, I avoid crashes with libcmt.lib. So I compile my selfmade files and then link the .obj files and .libs and I get error LNK2001: unresolved external symbol _errno. The place where I get this error from is in one file in mylib. I checked, that it includes header errno.h. If I remove linker option /NODEFAULTLIB:libc.lib, this error of _errno disappears, but I get lots of errors, because libc and libctm define same functions. Or if I make it single threaded, the problem is with _begingthreadex and _endthreadex. I don't understand. Why doesn't the linker realize errno? :confused: Could it be because of messing with C and C++? -Janetta
The way out of this dilemma is to have both componentes (the MFC program and the lib) compiled for the same version of the C run-time library. Go to the project settings for your MFC app and select (in the first tab) "Use MFC in a static library". Then go to the C/C++ tab, category "Code generation" and set "Use run-time library" to "Multithreaded". Good luck. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Hello, Still struggling with the linker. Many things have been solved, but still (at least) one left. So, I have mylib.lib, which is written in C and I'm using it in my console program, that uses also MFC. I have the source code of that lib, but I can't change it. I use makefile for compiling and linking. I have (among others) compile options /TP /MT, so it's C++ and multithreaded. With a linker option /NODEFAULTLIB:libc.lib, I avoid crashes with libcmt.lib. So I compile my selfmade files and then link the .obj files and .libs and I get error LNK2001: unresolved external symbol _errno. The place where I get this error from is in one file in mylib. I checked, that it includes header errno.h. If I remove linker option /NODEFAULTLIB:libc.lib, this error of _errno disappears, but I get lots of errors, because libc and libctm define same functions. Or if I make it single threaded, the problem is with _begingthreadex and _endthreadex. I don't understand. Why doesn't the linker realize errno? :confused: Could it be because of messing with C and C++? -Janetta
Janetta wrote: Could it be because of messing with C and C++? Yes it could. Try doing this:
extern "C"
{
#include "header_written_in_C_used_from_c_plus_plus"
}This will inform the C++ compilers to use C calling conventions, not C++ ones which are by default. Best regards, Alexandru Savescu