I wrote a client program and a server program, that uses the NTL library and Boost::Asio, to do client/server communication for an integer factorization application, in C++.
Both sides consist of several headers and cpp files. Both project compile fine individually on Windows in Visual Studio. All I did, was add the include path of NTL and Boost to both projects:
Additional include paths: "D:\Downloads\WinNTL-5_5_2\include";D:\boost_1_42_0
Furthermore, for both projects, I added the two library paths to both projects in VS:
Additional library directories: D:\boost_1_42_0\stage\lib;"D:\Documents\Visual Studio 2008\Projects\ntl\Debug"
And added under Additional dependencies:
ntl.lib
As said, it compiles fine on Windows. But when I put the code on a Linux machine provided by university, I try to compile with the following statement
c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include -I/appl/htopopt/Linux_x86_64/boost_1_43_0/include client_protocol.cpp mpqs_client.cpp mpqs_sieve.cpp mpqs_helper.cpp -o mpqs_helper -L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl -L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm -L/appl/htopopt/Linux_x86_64/boost_1_43_0/lib -lboost_system -static
Upon doing this, I get a huuuge error, which I posted here. Any idea how to fix this, please??
You are getting lots of errors to do with missing pthread symbols. Try adding
-lpthread
to your link line.
I'm not sure, but I suspect you can't do multi-threading in a staticly linked binary.
Related
I've managed to to use mpfr-mpir-gmp in CodeBlocks but I want to in eclipse C++:
When I compile the code it compiles and build but if I run the project it says: "error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory".
So can anyone show me how to configure eclipse to use gmp-mpifr-mpir correctly?
If I compile from a terminal:
g++ -lmpir -lmpfr -lgmp myEclpiseMPFRMPIRproj.cpp
then :
./a.out
It works fine and doesn't complain about the same problem. So I think I don't know how to pass those flags -lgmp, -lmpir -lmpfr.
Thank you.
I've figured it out after thousands of attempts without giving up. I am happy to share it for someone who may face the same problem:
When I've built and installed "gmp, mpfr, mpir" I've used sudo make install so the library is in /usr/local thus when I create a project with Eclipse-CDT everything is there only I add the flag to the linker:
Project->properties->C/C++ Build->Settings->GCC C++ Linker->Command and add:
g++ -lgmp -lmpir -lmpfr
Apply and Close. Now build and run. It works fine!
N.B: The problems I've faced already because I've add the library paths and files and include paths so I've removed them all.
I've been trying to learn how to use NetBeans as a C++ development environment. I installed NetBeans 8.2, installed MinGW, and compiled a simple Hello World program to make sure everything works. I then decided to try to compiler an old OpenGL project (based on this tutorial) that I had up-and-running in Visual Studio. Unfortunately, I keep getting errors saying the linker can't find the glew32 or glut32 library files:
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglew32
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglut32
As best as I can tell, however, I've set all of the necessary linker options;
screen-shot here.
What am I missing here?
My project's compile command as stated in the output pane:
g++ -o dist/Debug/MinGW32-Windows/opengl_tutorial build/Debug/MinGW32-Windows/nbproject/Main.o build/Debug/MinGW32-Windows/nbproject/ReadTGA.o -L\"C\:/C++\ Libraries/glew-1.13.0/lib/Release/Win32\" -L\"C\:/MinGW/lib\" -L\"C\:/C++\ Libraries/glut-3.7/lib\" -lglew32 -lglut32 -lglu32 -lopengl32
Things I've Tried
Removing spaces from external libraries' file path.
Placing .lib files in MinGW's lib folder (this gets rid of the original error and results in a slew of undefined reference errors).
Adding each library's bin folder to the Aditional Library Directories list and adding the DLLs to the Libraries list.
Switching between putting the file paths in the Aditional Library Directories list in quotes and not putting them in quotes (without quotes I get undefined reference errors).
Additional System Information
Operating System: Windows 7 Home Premium 64-bit SP1
Processor: 2GHz Intel Pentium Dual-Core
Try Adding environmental variables in
Properties->Run->Environment
In my case
Name=LD_LIBRARY_PATH
Value=/usr/local/apps/Java/jdk-14/lib:/usr/local/apps/root6.22.02Install/lib/root:/Work/Soft/general_classes/lib (and some more paths which no need to be pasted here)
I wrote a simple HelloWorld console application and compiled it on Windows 7 with MinGW compiler using one of these commands:
gcc -Wall -pedantic Hello.c -o Hello.exe
g++ -Wall -pedantic Hello.cpp -o Hello.exe
However the compiler links some own dynamic libraries into the app and when i copy the executable into another computer with Windows 7, which does not have MinGW installed, i'm getting missing library error. On Linux this problem is solved by package system, which automatically installs all needed libs, but in Windows you surely don't want to tell your users to install MinGW in order to run your program.
So my question is: How do i link all libraries properly and what else do i have to do to make my application run independently?
Although i believe, this must be a fundamental problem to all Windows programmers, i have been unable to find any answers on the internet (maybe i just don't know how and what to search).
It was in the FAQ at some stage, but now I seem to find it only on this page:
Why I get an error about missing libstdc++-6.dll file when running my program?
GCC4 dynamically link to libgcc and libstdc++ libraries by default
which means that you need a copy of libgcc_s_dw2-1.dll and
libstdc++-6.dll files to run your programs build with the GCC4 version
(These files can be found in MinGW\bin directory). To remove these DLL
dependencies, statically link the libraries to your application by
adding "-static-libgcc -static-libstdc++" to your "Extra linking
options" in the project settings.
Try this,
g++ -static-libgcc -static-libstdc++ -Wall -pedantic Hello.cpp -o Hello.exe
I'm afraid to say that with all of the applications installed on my machine, it's easy to identify which ones were built with MinGW. The telltale sign is a folder filled with libraries.
Check to see if the libraries that you need are distributable, and then simply include them in your .exe directory.
Although you may have other applications installed on user's machine, and some of them may contain the libraries that you need, there's a good chance that your application wont be compatible with them. This is why asking your users to install MinGW would be unlikely to work anyways.
Im learning c++ and I compile from the command line. I have a problem when it comes to trying to add 3rd party libraries. I cant seam to figure out the linker system. Does anyone know a good tutorial or something like that?
For example I want to play around with the SDL2 library and ill use a command like this.
c++ -I/Library/Frameworks/SDL2.framework/Headers -L/Library/Frameworks/SDL2.framework/ -lSDL2 helloworld.cpp
and I get the error ld: library not found for -lSDL2
You need to put the linking flags last on the line:
g++ -I/Library/Frameworks/SDL2.framework/Headers helloworld.cpp -L/Library/Frameworks/SDL2.framework/ -lSDL2
I found out the answer. The following command compiled correctly. The include statement had to be changed to...
#include<SDL2/SDL.h>
and the correct compile command is...
c++ -o helloworld helloWorld.cpp -framework SDL2
I could also have used g++. On my system both c++ and g++ are symlinks to the same gnu compiler which happens to be the latest version I have installed on the system.
the option -L is a unix linker option and does not work on a MAC. The dev's for GCC were kind enough to include MAC specific linker options in the form of -framework. These serve to follow the mac tradition of how and where they like to store libraries. You can link several frameworks together by separating them with a comma. So for example i could also do -framework SDL2,SDL2_mixer as long as my source has
#include<SDL2_mixer/SDL_mixer.h>
When compiling this default search location for libraries is /Library/Frameworks. The include statement is cross platform compatable and the mac gnu linker knows that if I say
#include<SDL2/SDL.h>
that that header will be found at /Library/Frameworks/SDL2.framework/Headers
The -IPATH option still works on mac and can be used to pass alternate search locations for header and source files just like it works in unix.
First, Background info: Ubuntu 10.10, gcc 4.4.5, C++, Qt Creator 2.3.1, FLANN.
Problem: Every time I compile my code I get an error saying 'undefined reference to [function from FLANN]'.
Explanation: I've been working on a GUI in Qt Creator that will utilize a few classes I built that include references to the FLANN library (not necessarily that important to know). Everything was going smoothly until I incorporated these classes and their header files, of course. I added the library to the .pro file just in case, but that didn't solve my problem. I narrowed down the situation to how Qt is making the files as compared to how I was making the files when I was testing my classes with a Makefile:
My Makefile: g++ -g process_stuff.o driver.o -o test.exe /usr/local/lib/libflann_s.a
I'm appending this library to the end of the gcc command, and it works perfectly. Further, if I remove the /usr/local/lib/libflann_s.a I get the same error making it myself that I got out of Qt.
Question: What exactly am I doing by including the library at the end of my gcc calls, and what can I do to have this happen in Qt Creator? All help is appreciated, and thanks in advance.
The short answer to what you're doing by adding the library at the end of the gcc command is telling the build system where it can find the library and what library you want to link into your code. The -L part indicates the path to libraries and the -l is the name of the library you wish to link against. Both of which I suspect are not being included in your Qt Project file, which is why it isn't building when you're running it normally. You can add the two in the project as:
INCLUDEPATH += $$quote(/usr/local/include)
LIBS += $$quote(-lflann_cpp_s) \
$$quote(-L/usr/local/lib/)
External libraries are usually provided in two forms: static libraries and shared libraries. Static libraries are the ‘.a’ files . When a program is linked against a static library, the machine code from the object files for any external functions used by the program is copied from the library into the final executable.
But moments later.... unix:!macx:!symbian: LIBS += -L$$PWD/../../../../usr/local/lib/ -lflann_cpp_s Upon fixing that to: unix:!macx:!symbian: LIBS += -L$$PWD/../../../../usr/local/lib/ -lflann_s
The Qt library wizard decided to include the wrong file as the library. After changing the file, everything works.