MSVC library linking with MinGW - c++

I have dll libraries from specific SDK compiled with MSVC '08 while using MinGW. And yes, I've got undefined reference.
undefined reference to `Some::NameSpace::Here::Class::method()'
In my project I'm using MinGW comliler with Qt (just because I'm making cross-platform app) and Linux libraries provided with SDK works just fine.
1) I've tried using pexports tool as in mentioned in MinGW FAQ but got no success. Still same undefined reference (no changes in errors masseges).
In my .def file I've got lines like:
?Method#Class#Here#NameSpace#Some##QAE_NIIGW4eReturnType#234##Z
2) Also extern "C" wasn't helpful. I surrounded with it every SDK .h include where it was possible (one header contains template definitions, so I wasn't able to surround it).
Strange thing is, that instead of:
undefined reference to `_imp___ZN6IClass6Methodci'
I got:
undefined reference to `Some::NameSpace::Here::Class::method()'
In function `ZN11MyClass21MethodEv':
So I think I messed up with name mangling.

Related

Automatically resolve undefined references from missing library with stubs?

I am building some unit testing stuff for a C/(C++) project that was developed for MSVC. I need to port it to g++ / MinGw. There is a library (DLL) that was build with VS. I can not get this library to link with the rest of the code, i always get undefined reference errors. It seems that the name mangeling between MSVC and g++ not compatible. Unfortunately I can not recompile the library with g++ because it uses some Microsoft Stuff that is incompatible with g++ (MFC/AFX).
So I wonder if there is any way to tell g++ to replace all undefined references with simple stub functions that just return 0 or Null.
Because I dont really need any of the functions, and I won't even call functions that call any of the missing functions. I just want to have something there so that the project compiles without changing the code that i want to test.
Is there any way to do that? Is there a tool that maybe extracts all the exposed functions and creates a replacement lib that only contains the stub functions?

undefined references cygwin with stdcall-fixup

I'm building something using Cygwin 32 bit. It's quite large so it has a couple of header files defined in their own .cpp files. I'm even using a few c++ boost headers, linking them. I'm doing this on x64 Eclipse Luna. The project is comprised of a mix of C and C++ files. Every time I build the project I keep getting undefined references errors, for all functions in the header files, including those from boost, despite me having linked the boost libraries correctly. Unfortunately, I don't have enough reputation to attach a screenshot(doesn't make any sense). But below is a sample of the errors. I have even tried linking using option enable-stdcall-fixup to no avail.
./caches.o:caches.cpp:(.text+0x1957): undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
./caches.o:caches.cpp:(.text$_ZNK5boost10filesystem16filesystem_error4whatEv[__ZNK5boost10filesystem16filesystem_error4whatEv]+0xa2): undefined reference to `boost::filesystem::path::codecvt()'
./fscore.o:fscore.cpp:(.text+0xa1): undefined reference to `btree_init()'
Please help.
Sincerely, batman

Cannot use LibHaru because cannot find the reference of zlib

I am trying to build a program that will hopefully create dynamic .pdf files. I have actually developed a similar project with PHP for web, but now I want to write it with C++.
This resulted me to rebuild those three libraries (zlib, libpng and libharu) more than time times for the last four days. I have read all the relevant entries in the web (including this stack overflow entry) I understood that my problem is that the compiler cannot find zlib (maybe I understood the problem wrongly)
I want to explain what I've done. Please note that I'm using Codeblocks IDE with GNU GCC C++ Compiler (MingGW) in Windows 7. First, I compiled zlib 1.2.7 and created my zlib.a static library file (I'm using static libraries). Secondly, I compiled libpng 1.5.13 and created my libpng.a. Thirdly, I compiled libharu (snapshot) and created my libharu.a static library file. Then I added those library files to my project. (I did everything explained in here). And at last, compiled my project.
Well, I shall say I did those all steps more than ten times, changing some small things, but everytime I am getting an error. I have even tried the official examples in libharu.org.
The most weird thing is that my error is NOT stable. Nearly everytime I got different errors! But mostly it was related with hpdf_streams.c.
My recent log file:
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xd4a): undefined reference to `deflateInit_'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xdfa): undefined reference to `deflate'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xe78): undefined reference to `deflateEnd'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xee2): undefined reference to `deflate'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xf7e): undefined reference to `deflateEnd'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xfb7): undefined reference to `deflateEnd'
C:\Libs\libharu-201301131604\libharu.a(hpdf_streams.o):hpdf_streams.c:(.text+0xff1): undefined reference to `deflateEnd'
We just had this issue. You need to recompile zlib with WIN_API off. Or use the dll's and not the static library.

g++ linking issues: undefined reference to functions

I used CMake and Visual C++ to build the HyDE library. Then, still in VC++, I was able to successfully create code and build an executable that links into HyDE.lib and the HyDE header files.
I then discovered that in order to work with others at my company, it would be preferable to develop in Eclipse CDT. Knowing very little about Eclipse CDT, I created a default hello world project, deleted the code and then dumped in all of my code into the src folder. Then I attempted to change the includes and lib path and libs to mirror what had worked in VC++. At this point everything seems to compile, but I get an error in linking:
/cygdrive/c/EclipseWorkspace/425HyDE/Debug/../src/FS5HyDE.cpp:16: undefined reference to `HyDEAPI::HyDE::HyDE(HyDESystemModel::SystemModel*, bool)'
(There are many more errors like this, all referring to HyDE methods.) Here is what is being run at the command line:
g++ -L"C:\Progra~1\boost\boost_1_42\lib" -L"C:\EclipseWorkspace\HyDE" -o"425HyDE.exe" ./src/Adapter_FS5HyDE.o ./src/EPSCommands.o ./src/EPSCurrentSensor.o ./src/EPSFault.o ./src/FS5HyDE.o ./src/HyDEObservation.o ./src/MCDH.o ./src/MCDH_Module.o ./src/PDBComponent.o ./src/PowerSystem.o ./src/Program.o ./src/SSPCComponent.o ./src/Telemetry.o ./src/TelemetryReport.o -l:libboost_thread-vc90-mt-gd-1_42.lib -lHyDE
This is definitely not a library ordering problem because I've the other ordering as well (there are only two). Is it possible that there is a problem with compiling HyDE.lib in VC++ (which uses a Windows compiler) and compiling my program with g++? Could there be a problem in the way that Eclipse CDT is autogen'ing the makefiles? Any other ideas?
(Note: there appear to be plenty of others questions on SO with similar problems, but after reading through them I have yet to find one that addresses my problem.)
Classic missing symbol error. Which source file defines:
HyDEAPI::HyDE::HyDE(HyDESystemModel::SystemModel*, bool)' ?
Was this file added to the compilation? Can you spot it on the command line you pasted?
If this symbol belongs to an external library, after adding the directory path with -L , you could add the name of the specific library you want to link with your program using -l.
I'm going to suggest that you try to add to the compilation command the directory path to HyDE.lib, followed immediately by the library name, like this:
-L"C:\path_to_hyde_library" -l:HyDE.lib
and then tell us what happened.
Solution: Since the HyDE library was compiled with the Visual Studios compiler and I'm attempting to build the code that links to it with the Cygwin toolchain the two compilers use different name mangling schemes so that the latter linker can not find the expected symbols in the HyDE library. The only solution that I've found is to recompile the HyDE library with the Cygwin toolchain or compile the new code with whatever compiler Visual Studios is using. (grumble grumble)
./src/FS5HyDE.o and ./src/HyDEObservation.o should be the latest parameter if other object files (*.o files) need them, it means that the most needed object files should be appeared as last as possible in the parameters list.

Port from gcc 3.3.3 to 4.1.0, C++ templates, undefined reference to

Our application makes use of C++ templates in a number of places. I am currently attempting to port from gcc 3.3.3 to 4.1.0 and am encountering issues. I have recreated the problem in a small shared library and executable. I am building the share library Ok, but the executable fails to link with the following:
undefined reference to `MyNumber<int>::~MyNumber()'
undefined reference to `MyNumber<int>::MyNumber(int)'
undefined reference to `MyNumber<int>::number()'
I am not using the template classes directly within the executable and would have expected this all to be encapsulated within the implementation within the shared library (probably naively so).
The problem only appears to show when working with a shared library. When I build our application on SLES 11 (gcc 4.3.2) most of my issues appear to be resolved but I still receive a number of the following:
undefined reference to `vtable for MYCLASS<T1, T2>'
This all when linking the executable to the shared libs.
It's a painfully obscure message, but it means you didn't define a virtual function, See here
I had a similar problem, and resolved it by implementating functions in the header file, not in a cpp file.
Salu2.
Without knowing more about your source code this is very hard to answer. However asking this particular question on the gcc mailing list may yield better results, as the people who work on gcc know all the intricacies better than everyone else.
Thanks for the comments. I removed the -frepo and -fno-impicit-templates from my compile/link options and was good to go.