1

I have multiple static libraries created with Visual Studio and Visual C++ compiler.

I am also using a CxxTest for unit testing. I created tests in .h files and generated test runner file runner.cpp.

Next thing I need to do is to compile that runner.cpp file.

runner.cpp uses one of the libraries, CommonLib.lib. CommonLib.lib doesn't have any aditional library dependencies.

CommonLib.lib headers are in my CommonLib project's directory.

I tried to compile runner.cpp using next command:

g++ -o runner.exe runner.cpp -L../x64/Release -l:CommonLib.lib -I../CommonLib 
-I../cxxtest-4.4

In Release directory there is a CommonLib.lib and headers are in a CommonLib directory. cxxtest-4.4 directory contains CxxTest headers.

I am getting error:

undefined reference to `multiplyMatricesStandard(int**, int**, int, int, int**, int, int, int)

multiplyMatricesStandard is a function that has declaration in a header file located in a CommonLib directory. In same directory is also a cpp file that contains a definition for that function (I don't think cpp file's location really matters because I have created a static library).

I can't figure out why g++ can't see definition for a function.

Is there a problem if static library is not created with g++? If there is, how can i compile runner.cpp file without having to create static libraries with g++?

Nikola Lošić
  • 479
  • 1
  • 6
  • 18
  • 1
    [This](http://stackoverflow.com/a/3253827/1410711) tells us that .lib files are specific to VS compilers only. You might need .a files for CommonLib. – Recker Jun 05 '16 at 12:16
  • 1
    More [info](http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html) here. See if you can solve by trial and error. – Recker Jun 05 '16 at 12:19
  • 1
    Obvously your chances will improve dramatically if you use VS to build when relying on those dependencies. I would be surprised if you could succeed using g++ linking those .lib files. – user2672165 Jun 05 '16 at 12:26
  • I have the same problem when I compile with VS compiler using cl command.. I managed to to fix it by specifying all needed files to the g++. I have other problem now with CxxTest, I can't link because runner.cpp doesn't have main. By documentation it seems like main should be defined somewhere else automatically and I should be able to compile, but that is not the case. I posted another question for this problem: http://stackoverflow.com/questions/37644452/cxxtest-compiling-missing-main – Nikola Lošić Jun 05 '16 at 16:54

0 Answers0