So I have a problem that I cannot solve by myself (currently still thinking it through). So I've downloaded g++ and it++ libraries for my project and I've chosen Eclipse as my IDE. Everything worked fine, but then I had to overwrite some files in itpp directory (usr/include/itpp). After doing that I had around 100+ errors all saying "undefined reference to ..." and all of them seems to be coming from the files that were added to the library and I really need them. I've tried removing and downloading everything again, but it doesn't seem to work. It seems to be a linker problem and I'm pretty new to linking and stuff(didn't need it in the past) and I'm not to sure how to do it. As far as I can see, in the main .h file of itpp everything seems to be fine, every new .h file has been included and all of the added files are in the right folder. I hope I've made my point clear, but as my English is imperfect you might have some troubles with understanding my problems - if so please state it and I will make myself more clear.
Thanks in advance for any help!
#Edit:
After adding the command "g++ magisterka.cpp $(pkg-config --libs itpp)" under Project -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler, I'm left with only one error and that is make*** [src/name.o] Error 1, but I guess that's a problem to discuss in another thread.
#Edit2:
After all my solution was bad. Maybe all errors disappeared, but it was due to the fact that the command line I've mentioned above was wrong and the new error has occured due to the fact that it could not localize magisterka.cpp which is my main file. Therefore I have now 100 errors again. Will try to post a solution as soon as I get one.
#Edit3: Console
make all
Building file: ../src/CodeInstance.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/CodeInstance.d" -MT"src/CodeInstance.d" -o "src/CodeInstance.o" "../src/CodeInstance.cpp"
Finished building: ../src/CodeInstance.cpp
Building file: ../src/magisterka.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/magisterka.d" -MT"src/magisterka.d" -o "src/magisterka.o" "../src/magisterka.cpp"
Finished building: ../src/magisterka.cpp
Building target: magisterka
Invoking: GCC C++ Linker
g++ -L/usr/include/itpp -o "magisterka" ./src/CodeInstance.o ./src/magisterka.o -litpp
./src/magisterka.o: In function `main':
Related
There are similar questions but their answers did not work for my issue.
I have a c++ program with #include <boost/test/unit_test.hpp> on top (among other includes).
To compile correctly, if I understood, I should do the command:
g++ -g -L/path_to_boost_lib -lboost_lib myprog.cpp -o myprog.exe
If i do a locate, I get /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.
Hence I edited my call to g++ by doing:
g++ -g -L/usr/lib/x86_64-linux-gnu -lboost_unit_test_framework myprog.cpp -o myprog.exe
But I still get errors of the type undefined reference to boost::unit_test.
I also tried the option -I/usr/include/ which contains the boost folder, without success.
It's because of the order. The GCC linker goes through the artifacts left-to-right, and every unknown symbol it encounters in an object file must be resolved by an artifact occurring afterwards.
The right command is thus:
g++ -g myprog.cpp -L/usr/lib/x86_64-linux-gnu -lboost_unit_test_framework -o myprog.exe
See this answer for a more thorough explanation.
I suggest using a build tool like CMake that takes care of such low-level details for you.
I am creating a gcc shared library having a static library dependency.
I compile the parts for static library as following:
gcc -c -m64 -O2 -fPIC -std=c99 -Wall ms*.c //there are 10 C files, no warnings
Next I create a static library with:
ar rc static_lib.a ms*.o
Next I compile the parts for my program as following:
g++ -c -m64 -O2 -fPIC -std=c++14 -Wall ab*.cpp //there are 5 C++ files, just -Wunused-variable warnings
Then I create a shared library as following:
g++ -shared -g -Wall ab*.o static_lib.a -o shared_lib.so
in the normal case, this shared_lib.so will be called by a Ruby program using a foreign function interface. There is no problem if I do it on ubuntu or mac(.dylib), but if I try this on debian stretch I get an error related to the static library as if the configurations are not set properly. If I run the application without foreign function interface, such as creating a tester and running with the cpp file main function as following:
> g++ -o library_test ab*.o static_lib.a
> ./library_test
There is no problem!
My question is what kind of configuration for creating a shared library may be missing here to not get that undesirable behaviour. Especially on debian stretch 9.5!
Or is there a way that I can understand if there is a problem in the shared library.
From the comments, you indicate the problem is with a #define. Those are preprocessor directives. Libraries are for the linker.
You might be confused because g++ does include the preprocessor phase, and might call the linker depending on the requested output. Still, g++ follows the C++ language rules.
I have been trying to compile a simple C++ program with the googletest libraries. I have gotten this to work using g++, however the project will soon become large and I want to be able to automate the compilation using make. I installed GNU make for windows which I have tested on another program and it works. However when I try and use make to compile my googletest project I get the following error:
ld.exe: cannot find -lgtest
Here is the contents of my makefile:
all: test.exe
test.exe: main.cpp
g++ -o test.exe .\main.cpp .\sample1.h .\sample1.cc .\sample1_unittest.cc -ID:\...\gtest\include -LD:\D...\gtest\lib\ -lgtest_main -lgtest -Wall
clean:
rm test.o test.exe
The weird thing is that if I run the same code from the command line, as follows, it works perfectly an I end up with my test.exe.
g++ -o test.exe .\main.cpp .\sample1.h .\sample1.cc .\sample1_unittest.cc -ID:\...\gtest\include -LD:\D...\gtest\lib\ -lgtest_main -lgtest -Wall
Does anyone know what this could be caused by and how to fix it?
Ok, I managed to find the problem! I'm still not sure why this is the case but apparently in make you have to specify paths like so:
-LD:\...\gtest\lib
And not like this (note the extra ):
-LD:\...\gtest\lib\
The error message makes sense since it must have been trying to search for the library in a path that looks something like this:
-LD:\...\gtest\lib\\
Which would obviously not work. I guess what threw me off was that the code worked when executed from the command line. It took me a while to see the inconstancy in my path specification and figure out that make doesn't want the extra '\'. Hopefully this will prevent someone else for wasting as much time as I did.
I am trying to build a project with many depencies. For simplying, let's say 2 projects "Mathematics" and "PhysicalProperties which depends on "Mathematics". These projects are build in libraries static and dll. So we need to get libMathematics.a, Mathematics.dll libPhysicalProperties.a and .dll...
So "PhysicalProperties" needs Boost and the libMathematics.a...
I'm working with Eclipse Indigo and the toolchain is MingW 4.5.0.
The build of "Mathematics" works but not the build of "PhysicalProperties" which gave a linker errors : "undefined reference to function..." in "Mathematics"
I check the dependencies but everything is ok, the function is really declared and defined and the library Mathematics is linked. I check also the symbols in the libMathematics.a and found the function that linker didn't find... So if you 've got ideas, i wil be glad to read you ?
Below are the errors when building :
//===========================================================================
Building file: ../WaveTools.cpp
Invoking: GCC C++ Compiler
g++ -I"C:\Users\StageTahar\Desktop\Lucid\Common\Includes" -I"C:\Boost/include/Boost-1_49/" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"WaveTools.d" -MT"WaveTools.d" -o "WaveTools.o" "../WaveTools.cpp"
Finished building: ../WaveTools.cpp
Building target: ElectromagneticWave.dll
Invoking: GCC C++ Linker
g++ -s -L"C:\Users\StageTahar\Desktop\Lucid\Common\Libraries" -L"C:\Boost/lib" -shared -Wl,--out-implib=libElectromagneticWave.a -o "ElectromagneticWave.dll" ./ElectromagneticWaveImplementation.o ./WaveTools.o -lMathematics -lboost_wserialization-mgw45-mt-d-1_49
./ElectromagneticWaveImplementation.o: In function `ZNK11JonesVectorIfE12getIntensityEv':
C:\Users\StageTahar\Desktop\Lucid\Engines\ElectromagneticWave\Debug/../WaveDefinitions.h:124: undefined reference to `float norm<float>(ComplexT<float> const&)'
//=========================================================================================
I'm trying to set up my Netbeans IDE so that it is capable of compiling wxWidgets projects.
There is very similar question:
Setup wxWidget in Netbeans 6.1 C++ On MS Windows?
but the answer is not working for me. And the mentioned versions are a bit outdated.
I use the mingw package for compilation.
There is no problem compiling a small hello World App from the console using this command in mysys:
$ g++ hello.cpp `wx-config --libs` `wx-config --cxxflags` -o hello.exe
So here's what I tried in Netbeans:
Project properties:
C++ Compiler -> Additional Options: wx-config cxxflags (surrounded by backticks)
C++ Compiler -> Include directories: installation_Path/include
Linker -> Additional Options: wx-config --libs (surrounded by backticks)
The command lines Netbeans creates when I try to compile seem to be correct to me
g++.exe `wx-config --cxxflags` -c -g -I/D/lib/wxWidgets/include -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
This compiles without errors
g++.exe `wx-config --cxxflags` `wx-config --libs` -o dist/Debug/MinGW-Windows/wxwidgetstest build/Debug/MinGW-Windows/main.o -L/D/lib/wxWidgets/lib/gcc_lib
But during the linking process I get loads of errors...
Questions:
Does anybody have a working configuration for compiling wxWidgets Projects from within Netbeans and can help me out
Or does anybody see an error in the command lines could be the reason for the linking problems ?
Thank you very much!
I finally found the solution, and wrote a guide for anyone who might encounter the same problem in the future.
wxWidgets wiki: Compiling using Netbeans