I have just installed GLFW on OS X 10.9. The headers were installed to /usr/local/include and the library was installed in /usr/local/lib.
I am wondering what else I would have to do to get my C++ program to include the headers like #include "GLFW/glfw3.h" rather than specifying the whole path like #include "usr/local/include/GLFW/glfw3.h".
Same thing goes for the library because as of now I can't even link the library using -lglfw3. Thanks in advance.
You would pass -I /usr/local/include to the compiler as preprocessor flag, and -L /usr/local/lib to the compiler as linker flag. So to build a single source application small.cc compile it as
g++ -Wall -I /usr/local/include -L /usr/local/lib \
small.cc -o small -lglfw3
If building with make just have
CXXFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
in your Makefile
If using shared libraries, add once /usr/local/lib to /etc/ld.so.conf and run ldconfig (at least on Linux).
Related
I am using boost/multiprecision/cpp_int.hpp within class of a cpp file boost.cpp
My main in in practice.cpp
How do i add the Boost into the make file
The current make file looks like this:
practice.exe : practice.o
g++ -Wall -O2 practice.cpp -lws2_32 -o practice.exe
practice.o : practice.cpp
g++ -c -O2 -Wall practice.cpp
clean:
del *.o
del *.exe
So, the general idea is to just system install boost and let the compiler find it in the default include paths.
E.g. on a debian
apt install libboost-all-dev
Should be enough. Boost Multiprecision itself is header-only. So if you only need cpp_int, cpp_dec_float and cpp_bin_float, you're done. You might want GMP/MPFR support, in which case you need to link those libraries with the additional linker flags -lgmp or -lmpfr.
If you need Serialization support, also link -lboost_serialization which would be installed in the default library paths with the system-wide Boost package we installed at the start.
I was trying to build a binary for the protocol buffers C++ AddressBook tutorial. I compiled the protocol buffers successfully, but when I was building the binary with g++, I used pkg-config to get cflags and libs, and it failed to locate the necessary headers. I manually passed all the necessary flags, include directories, library directories, etc. to g++ and it worked.
pkg-config --cflags protobuf returns "-pthread"
pkg-config --libs protobuf returns "-lprotobuf -pthread -lpthread"
Meanwhile, protobuf.pc lists:
Cflags: -I${includedir} -pthread
Libs: -L${libdir} -lprotobuf -pthread -lpthread
I confirmed that the variables are set correctly with --variable=(include/libdir), and when using the --debug option, it confirms variables are set. However, it also shows that the -I and -L options are removed. The following is truncated debug output.
...Pasing pacage file protobuf.pc...
...Variable declarations...
Unknown keyword 'Libs.private' in protobuf.pc
...More variable declarations...
Adding 'protobuf' to list of known packages
Package protobuf has -I/usr/include in Cflags
Removing -I/usr/include from cflags for protobuf
Package protobuf has -L /usr/lib/x86_64-linux-gnu in Libs
Removing -L /usr/libx86-64-linux-gnu from libs for protobuf
I'm trying to use X86_64-w64-mingw32-g++ (packaged in Archlinux's MingW package) to cross compile some C++ code into an Windows executable, however I'm having trouble getting past some issues.
I'm calling
x86_64-w64-mingw32-g++ -o build_win/asm build_win/asm.o build_win/asm_lib.o build_win/socket_boost.o -I../extra/etc -fopenmp -lrt -std=c++11 -g -lboost_system -lboost_serialization
from a makefile, but I get thrown the errors:
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lrt
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_system
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_serialization
This works fine with native g++, so exactly do I have to change for mingw to compile?
EDIT: I have mingw-w64-boost package installed, which includes boost libraries pre-compiled and ready to be linked. However, it seems the naming convention is a bit different, and -lboost_system for example becomes -llibboost_system-mt (not exactly sure what the -mt suffix entails).
Problem is I can't find the mingw counterpart for -lrt. I've tried with both -lrtm and -lrtutils but in both cases I get:
[...]
undefined reference to `__imp_getsockopt'
Are you sure that -lboost_system and other libraries are present in the same directory as makefile ?
If not then please include -L flag which indicates the location of your library.
For example:
-L /path_openmp -fopenmp -L /path_boost_system/ -lboost_system -L /path_serialization -lboost_serialization
Moreover, you need not include -I and -g flag when creating an executable from .o files. These are needed when you create .o from .cpp files.
There is no rt library on Windows.
You are missing -lws2_32.
$ x86_64-w64-mingw32-nm -A /usr/x86_64-w64-mingw32/lib/*.a 2>/dev/null | grep getsockopt | grep " T "
I've been trying to go through Boost tutorials but I got stuck at linking the filesystem library.
I have Ubuntu 12.10. Installation wasn't that hard
sudo apt-get install libboost-all-dev
This put all headers in /usr/local/include and compiled sources in /usr/lib/
[--headers]
[--binaries]
I wrote this program [--program]. When I tried to compiled it
g++ -g tut1.cpp -o tut1 -lboost_system -lboost_filesystem
got this errors: [--errors].
After a little search on http://www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html
I tried this:
g++ -g -I /usr/local/include/boost/ tut1.cpp -o tut1 -L /usr/lib/libboost_filesystem.a -lboost_system -lboost_filesystem
but didn't have luck. I had the same errors.
Since I cannot put more than 2 links in the post, here are all links
http://pastebin.com/DakVFn12
I found the answer myself here:
http://www.richelbilderbeek.nl/CppLinkErrorUndefinedReferenceToBoostFilesystemDetailGet_current_path_api.htm
Looks like binaries weren't in /usr/lib but in /usr/local/lib.
So the correct command for compilation would be:
g++ -g tut1.cpp -o tut1 -L/usr/local/lib/ -lboost_filesystem
#Yuushi, that was 1 problem.
The -L command should be the base path where the libraries are contained, not the path to a specific library. Try with -L /usr/lib/ instead.
I installed these two libraries: glut and curl.
sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install freeglut3-dev
when I have to compile a program I use:
g++ -o executable file11.cpp file2.cpp -lglut -lcurl
and it works!
How can I know where the linker search for "-lglut" or "-lcurl"?
"-lsomething" correspond to a path, How can I find out?
It checks /lib, /usr/lib, and any paths passed to -L.
The linker will look in directories specified by the -L option and in standard system directories, which are usually /lib and /usr/lib. Although you're not using any -L options GCC will usually pass some to the linker so it can find GCC's own libraries (e.g. the C++ standard library) unless you use -nostdlib. GCC will also add -L options for the contents of the LIBRARY_PATH environment variable.
To see the options GCC passes to the linker you can compile with -v (for verbose) and to see which libraries the linker uses you can pass -Wl,--trace to GCC, which causes it to pass --trace to the linker, which makes it output something like:
/usr/bin/ld: mode elf_x86_64
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/crtbegin.o
/tmp/ccJHrbSx.o
-lglut (/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libglut.so)
-lcurl (/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/libcurl.so)
-lgcc_s (/usr/lib/gcc/x86_64-redhat-linux/4.7.2/libgcc_s.so)
/lib64/libc.so.6
(/usr/lib64/libc_nonshared.a)elf-init.oS
/lib64/ld-linux-x86-64.so.2
-lgcc_s (/usr/lib/gcc/x86_64-redhat-linux/4.7.2/libgcc_s.so)
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crtn.o
This shows the libraries that were found for the -lglut and lcurl libs on my system. The libs are found in that path because on my system GCC passed -L/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64 to the linker (shown by compiling with -v)
You can canonicalize those paths using readlink
$ readlink -f /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/
/usr/lib64/
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
It just turns the string into a filename, and checks normal locations for it, it seems.
Try
ldd /path/to/your/executable