using static library for C code in Visual studio 2005
-
Hi, I am working on a simple win32 console based application in C in visual studio2005. My application uses a third party static library. So I have included the path of the library and the library in additional dependencies for linker input. My code compiles and works fine if I compile this code as C++ code. But If I want to compile this as C code, for the same library functions, I am getting unresolved external symbols. Can any one please let me know, if I have to change anything for this library to compile as C code.?
Regards, Sunil Kumar
-
Hi, I am working on a simple win32 console based application in C in visual studio2005. My application uses a third party static library. So I have included the path of the library and the library in additional dependencies for linker input. My code compiles and works fine if I compile this code as C++ code. But If I want to compile this as C code, for the same library functions, I am getting unresolved external symbols. Can any one please let me know, if I have to change anything for this library to compile as C code.?
Regards, Sunil Kumar
Its possible to do that but depending on your unresolved external symbols you might have to use a thin layer of C++ between your C code and the C++ library.
-
Hi, I am working on a simple win32 console based application in C in visual studio2005. My application uses a third party static library. So I have included the path of the library and the library in additional dependencies for linker input. My code compiles and works fine if I compile this code as C++ code. But If I want to compile this as C code, for the same library functions, I am getting unresolved external symbols. Can any one please let me know, if I have to change anything for this library to compile as C code.?
Regards, Sunil Kumar
The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****Malli_S wrote:
The way out for this is use dynamic loading of that DLL.
DLL?
-
Hi Malli, thanks for the reply. So in that case,by using dynamic loading of library using LoadLibrary, we can avoid this even the library is compiled as C++.?
Regards, Sunil Kumar
-
Malli_S wrote:
The way out for this is use dynamic loading of that DLL.
DLL?
-
Chris Losinger wrote:
DLL?
I meant to say using LoadLibrary().
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****but the post says nothing about a DLL. it says "static library".
-
but the post says nothing about a DLL. it says "static library".
-
Hmm. I should have mentioned about the DLLs. I was trying to focus on dynamic linking, rather than static linking. My mistake. I missed that.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:**** -
Hi, I am working on a simple win32 console based application in C in visual studio2005. My application uses a third party static library. So I have included the path of the library and the library in additional dependencies for linker input. My code compiles and works fine if I compile this code as C++ code. But If I want to compile this as C code, for the same library functions, I am getting unresolved external symbols. Can any one please let me know, if I have to change anything for this library to compile as C code.?
Regards, Sunil Kumar
If it was me I would put a C function wrapper around it. And compile that at a library. Then your app uses the second library. The dynamic loader solution works but it means that you must deal with the name mangling yourself rather than letting the compiler do it. And if the C++ requires an C++ idioms, like creating a class, then doing thing via dynamic method calls is going to be difficult.
-
If it was me I would put a C function wrapper around it. And compile that at a library. Then your app uses the second library. The dynamic loader solution works but it means that you must deal with the name mangling yourself rather than letting the compiler do it. And if the C++ requires an C++ idioms, like creating a class, then doing thing via dynamic method calls is going to be difficult.
-
But it's a third party library. He might not have the source code for that.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****Hi, One more thing is,it compiles properly for C++ in debug mode. But in Release mode the same unresolved external errors, I am getting for the functions. I have mentioned the project properties in Release mode same as in Debug mode. But still it is unable to link to the functions in the library. Why this behavior.Does it mean, the library is compiled in debug mode? Regards, Sunil.
Regards, Sunil Kumar
-
But it's a third party library. He might not have the source code for that.
[Delegates] [Virtual Desktop] [Tray Me !]
-Malli...! :rose:****