make error) Undefined reference to std::__cxx11::basic_string - makefile

When I command make, I got errors like this:
filter_block.cc:(.text+0x1c4): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
I found some solutions for this error, like adding -D_GLIBCXX_USE_CXX11_ABI=0, but I don't know how to add the command for make command.
The Makefile is written as:
.SUFFIXES: .c .cpp
CC = g++ -fopenmp
CFLAGS = -c -O2 -Wall -D_I386 -D_UNIX -fPIC -Wno-unused-result -std=c++11 -Wno-sign-compare
LFLAGS = -shared -O2 -o
LIBS = -llmi -lblas -lboost_regex -lpthread -lleveldb
How can I add -D_GLIBCXX_USE_CXX11_ABI=0 into Makefile?
*Ubuntu version = 14.04
*libstdc++ version
$ /sbin/ldconfig -p | grep stdc++
libstdc++.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
*gcc version
$ gcc --version
gcc (Ubuntu 5.4.1-2ubuntu1~14.04) 5.4.1 20160904
*ld version
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.26.1

Related

How do you compile the occi demo on ubuntu?

It's 2021, does Oracle not support modern operating systems that use compiler ABIs released over 6 years ago?
$ make -f demo.mk
rm -rf SunWS_cache
rm -rf cdemo81 cdemo81.o occidml occidml.o occiobj occiobj.o occiobjo* occiobjm* occiobj.h occiobjout.type
/usr/bin/gcc -c -I../include -DLINUX -D_GNU_SOURCE -D_REENTRANT -g cdemo81.c
/usr/bin/g++ -o cdemo81 -g cdemo81.o -L../../ -locci -lclntsh -lpthread
make -f demo.mk buildocci OBJS=occidml.o EXE=occidml
rm -rf SunWS_cache
/usr/bin/g++ -c -I../include -DLINUX -D_GNU_SOURCE -D_REENTRANT -g occidml.cpp
/usr/bin/g++ -o occidml -g occidml.o -L../../ -locci -lclntsh -lpthread
occidml.cpp:291: error: undefined reference to 'oracle::occi::SQLException::getMessage[abi:cxx11]() const'
occidml.cpp:63: error: undefined reference to 'oracle::occi::SQLException::getMessage[abi:cxx11]() const'
occidml.cpp:83: error: undefined reference to 'oracle::occi::SQLException::getMessage[abi:cxx11]() const'
occidml.cpp:106: error: undefined reference to 'oracle::occi::SQLException::getMessage[abi:cxx11]() const'
collect2: error: ld returned 1 exit status
The default libocci.so.19.1 is not compatible with g++ versions 5 and above. Please contact Oracle support to get the specially built libocci to work with g++ 5 and above.
For the supported Linux platforms, please try
make -f demo_rdbms.mk occidemos (for building all OCCI demos)
make -f demo_rdbms.mk occidml (for building just one demo like occidml)
make -f demo_rdbms.mk buildocci EXE=myapp OBJS=myapp.o (for a custom .cpp program)
The above is with a regular installation. You didn't mention which version of OCCI you are trying and the version of g++.

GCC Static Linking And Separate Loader

I'm trying to understand the process of static linking, loading of GCC:
I have the following toy program
#include "stdio.h"
int main() {
fprintf(stdout, "Hello World \n");
return 0 ;
}
I can compile it and run file as follows:
gcc -static -std=gnu99 -Wall -Wno-unused -g test.c -o test;
But as soon as I try to separate out the compile and linking process as follows:
gcc -static -std=gnu99 -Wall -Wno-unused -g test.c -c;
ld -o test -T link.lds test.o
where the link.lds is
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}
I get the error "undefined reference to stdouttest.o: In function `main':
test.c:(.text+0x7): undefined reference to `stdout'
test.c:(.text+0x1e): undefined reference to `fwrite'
If I try adding the flag -lc to ld, it tells me that it is not found. I've tried running gcc with -lc
and/or -static-libgcc but I have the same problem.
What am I doing wrong?
Do
gcc -v -static -std=gnu99 -Wall -Wno-unused -g test.c
and look for the collect2 tag.
In my case it is
collect2 --sysroot=/ --build-id -m elf_x86_64 --hash-style=gnu --as-needed -static -z relro -o test /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbeginT.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. /tmp/ccoR98Xr.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
You have to replace the temporary object file. In my case I replaced /tmp/ccoR98Xr.o with test.o. Then do
gcc -c -std=gnu99 -Wall -Wno-unused -g test.c
ld --sysroot=/ --build-id -m elf_x86_64 --hash-style=gnu --as-needed -static -z relro -o test /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbeginT.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. test.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
It links to the object files : crt1.o, crti.o, crtbeginT.o, crtend.o, and crtn.o.
It links to the libraires: libgcc.a, libgcc_eh.a, and libc.a.
You can replace --start-group -lgcc -lgcc_eh -lc --end-group with -lgcc -lc -lgcc_eh -lc if you like.
Knowing this we can simply this to
ln -s `gcc -print-file-name=crt1.o`
ln -s `gcc -print-file-name=crti.o`
ln -s `gcc -print-file-name=crtn.o`
ln -s `gcc -print-file-name=libgcc_eh.a`
ln -s `gcc -print-file-name=libc.a`
gcc -c -std=gnu99 -Wall -Wno-unused -g test.c
ld -m elf_x86_64 -o test crt1.o crti.o test.o libc.a libgcc_eh.a libc.a crtn.o
I did not use crtbeginT.o, crtend.o, and libgcc.a because it worked without them.
Take a look at this, strace does the job (show you the secrets) but you will soon realize there are tons of options in it... You need to link a few stuff together (from GNU C lib) to get your executable, not only your object... You can add grep 'exec' in the end to make it cleaner.
Uhhh, also you need to do this:
as obj.s -o obj.o
Use GNU assembler to convert your .s to .o then link with ld.

Telling ld where to look for dependent shared libraries during compilation

I'm trying to crosscompile some libraries for an ARM processor, specifically:
DirectFB, which depends on libpng, which depends on zlib.
Libpng is linked against zlib, but since the paths on the build system don't match the paths on the target system, ld can't find the zlib that libpng is linked against during the compilation of DirectFB.
I've reduced the issue to the following example:
testb depends on libb, which depends on liba.
Build liba:
gcc -Wall -fPIC -c a.c
gcc -shared -Wl,-soname,liba.so.1 -o liba.so.1.0 a.o
ln -fs liba.so.1.0 liba.so.1
ln -fs liba.so.1 liba.so
Built testa:
gcc -Wall -I. -L. testa.c -la -o testa
LD_LIBRARY_PATH=. ./testa
a: 0
Build libb:
gcc -Wall -fPIC -I. -L. -c b.c -la
gcc -shared -Wl,-soname,libb.so.1 -o libb.so.1.0 b.o
ln -fs libb.so.1.0 libb.so.1
ln -fs libb.so.1 libb.so
So far, so good. However, building testb fails:
gcc -Wall -I. -L. testb.c -lb -o testb
Results in:
./libb.so: undefined reference to `a'
collect2: ld returned 1 exit status
make: *** [testb] Error 1
So ld can't find the definition of a in liba, even though libb is linked against liba, and both are in the current directory, which is being passed with "-L."
Running gcc with -v results in:
gcc -v -Wall -I. -L. testb.c -lb -o testb
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
COLLECT_GCC_OPTIONS='-v' '-Wall' '-I.' '-L.' '-o' 'testb' '-mtune=generic' '-march=i486'
/usr/lib/gcc/i486-linux-gnu/4.4.3/cc1 -quiet -v -I. testb.c -D_FORTIFY_SOURCE=2 -quiet -dumpbase testb.c -mtune=generic -march=i486 -auxbase testb -Wall -version -fstack-protector -o /tmp/ccqAkMFb.s
GNU C (Ubuntu 4.4.3-4ubuntu5.1) version 4.4.3 (i486-linux-gnu)
compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128244
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.3/include
/usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed
/usr/include
End of search list.
GNU C (Ubuntu 4.4.3-4ubuntu5.1) version 4.4.3 (i486-linux-gnu)
compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128244
Compiler executable checksum: 2349e080d2b2f3f970047e63bbe98cb2
COLLECT_GCC_OPTIONS='-v' '-Wall' '-I.' '-L.' '-o' 'testb' '-mtune=generic' '-march=i486'
as -V -Qy -o /tmp/ccc6ux7S.o /tmp/ccqAkMFb.s
GNU assembler version 2.20.1 (i486-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.20.1-system.20100303
COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../:/lib/:/usr/lib/:/usr/lib/i486-linux-gnu/
COLLECT_GCC_OPTIONS='-v' '-Wall' '-I.' '-L.' '-o' 'testb' '-mtune=generic' '-march=i486'
/usr/lib/gcc/i486-linux-gnu/4.4.3/collect2 --build-id --eh-frame-hdr -m elf_i386 --hash-style=both -dynamic-linker /lib/ld-linux.so.2 -o testb -z relro /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o -L. -L/usr/lib/gcc/i486-linux-gnu/4.4.3 -L/usr/lib/gcc/i486-linux-gnu/4.4.3 -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../.. -L/usr/lib/i486-linux-gnu /tmp/ccc6ux7S.o -lb -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crtn.o
./libb.so: undefined reference to `a'
collect2: ld returned 1 exit status
make: *** [testb] Error 1
Setting LD_LIBRARY_PATH and/or LIBRARY_PATH to the current directory doesn't resolve the problem.
Compiling with -la works, but it shouldn't be necessary, since libb is linked against liba. For example, when linking against libpng in a native build environment (correct paths, library paths in ld.so.conf) doesn't require -lz.
Also, setting additional libs to link against is a pain, because I would have to patch the Makefiles for every compilation that depends on a lib that depends on another lib.
In summary, how do I tell ld where to look for dependent shared libraries during compilation?
My problem is similar to these two:
Cross-linking for ARM/QNX fails with indirect/transitive dependencies
How to resolve shared library linking during compilation( GCC )?
Neither suggests a solution which doesn't require the addition of -la, which in my opinion shouldn't be necessary.
Files used:
a.c:
int a() {
return 0;
}
liba.h:
#ifndef LIBA_H
#define LIBA_H
int a();
#endif
testa.c:
#include <stdio.h>
#include <liba.h>
int main() {
printf("a: %d\r\n", a());
return 0;
}
b.c:
#include <liba.h>
int b() {
return a();
}
libb.h:
#ifndef LIBB_H
#define LIBB_H
int b();
#endif
testb.c:
#include <stdio.h>
#include <libb.h>
int main() {
printf("b: %d\r\n", b());
return 0;
}
Makefile:
# Makefile for shared library test
all:
liba:
gcc -Wall -fPIC -c a.c
gcc -shared -Wl,-soname,liba.so.1 -o liba.so.1.0 a.o
ln -fs liba.so.1.0 liba.so.1
ln -fs liba.so.1 liba.so
testa: liba
gcc -Wall -I. -L. testa.c -la -o testa
runtesta: testa
LD_LIBRARY_PATH=. ./testa
libb: liba
gcc -Wall -fPIC -I. -L. -c b.c -la
gcc -shared -Wl,-soname,libb.so.1 -o libb.so.1.0 b.o
ln -fs libb.so.1.0 libb.so.1
ln -fs libb.so.1 libb.so
testb: libb
gcc -v -Wall -I. -L. testb.c -lb -o testb
runtestb: testb
LD_LIBRARY_PATH=. ./testb
clean:
# clean up
rm -rf *.o
rm -rf liba.s*
rm -rf libb.s*
rm -rf testa testb
You must add -la to linking phase of lb (second line below is essential):
$ gcc -Wall -fPIC -I. -L. -c b.c -la
$ gcc -L. -shared -o libb.so b.o -la
$ LD_LIBRARY_PATH=. gcc -Wall -I. -L. testb.c -lb -o testb
$ LD_LIBRARY_PATH=. ./testb
b: 0
Also -la on compilation isn't really required, I left it only because it was in your original example. Instead first line
$ gcc -Wall -fPIC -I. -L. -c b.c
will be enough.
Common rule is -- linker is guy, who need libraries, not compiler.

Boost static linking in unix

I am using the Boost library in Unix, GCC. I read the following topic: Boost static linking and added -static to my Makefile. However, this does not work.
Here is my Makefile:
all: nbbo
nbbo: nbbo.o reader.o
g++ -static -O3 -ffast-math -funroll-loops -ansi -pedantic-errors -L/usr/lib -lboost_filesystem -lboost_serialization -lboost_iostreams -lz -I /usr/include/boost -o nbbo nbbo.o reader.o
nbbo.o: nbbo.cpp
g++ -static -O3 -ffast-math -funroll-loops -ansi -pedantic-errors -I /usr/include/boost -c -o nbbo.o nbbo.cpp
reader.o: reader.cc reader.h
g++ -static -O3 -ffast-math -funroll-loops -ansi -pedantic-errors -I /usr/include/boost -c -o reader.o reader.cc
clean:
rm *.o
And here is the error message:
nbbo.o: In function `__tcf_10':
nbbo.cpp:(.text+0x3d9): undefined reference to `boost::serialization::extended_type_info::key_unregister() const'
nbbo.cpp:(.text+0x3e3): undefined reference to `boost::serialization::typeid_system::extended_type_info_typeid_0::type_unregister()'
nbbo.cpp:(.text+0x3fb): undefined reference to `boost::serialization::typeid_system::extended_type_info_typeid_0::~extended_type_info_typeid_0()'
etc
Which "UNIX" are you using? Using the -static flag should work fine on linux. But not on OSX. On OSX you have to remove the static flag and give the complete path to the library in order to link statically. I dont know how this would work on other "UNIXes"
eg.
g++ ..... /path/to/your/lib.a ... -o ..

Including boost libraries in make files

I'm learning Boost and am having trouble with my makes files.
Here is my basic makefile:
accesstimer: acctime.o btimer.o
g++ acctime.o btimer.o -o accesstimer
acctime.o: acctime.cpp btimer.h
g++ -c acctime.cpp
bentimer.o: btimer.cpp btimer.h
g++ -c btimer.cpp
When acctime.cpp has no boost filesystem elements in it this m,ake file works fine.
As soon as I add boost filesystem elements I obviously need to make references to the boost libray in the make file this is where I am having issues.
The following line works for a single file compilation:
g++ -I /usr/local/boost/boost_1_39_0 boosttest1.cpp -o bt1 /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a
Now I'm trying to integrate this into the make file. I've tried many based on what information I can find on the web but none are working this is my latest:
accesstimer: acctime.o bentimer.o
g++ acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c -I /usr/local/boost/boost_1_39_0 acctime.cpp /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Unfortunately it stlill can't find the Boost libraries, can anyone help?
thanks
Having read the advice of the people who've answered I've now got this:
accesstimer: acctime.o bentimer.o
g++ -L /usr/local/boost/boost_1_39_0 acctime.o /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
But this still fails to link.
This is the error message I'm getting:
g++ -L /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
acctime.o: In function boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)':
acctime.cpp:(.text._ZN5boost10filesystem6existsINS0_10basic_pathISsNS0_11path_traitsEEEEENS_9enable_ifINS0_13is_basic_pathIT_EEbE4typeERKS7_[boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)]+0x26): undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&)'
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
Following orsogufo's advice (thanks! much appreciated) now have this:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Looking better, but still can't quite find the library:
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt.a
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
I've double checked that location and the library is definately at:
/usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a
STill no joy, usimg this now:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0 -lboost_filesystem-gcc41-mt acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Getting:
g++ -L/usr/local/boost/boost_1_39_0/stage/lib/ -llibboost_filesystem-gcc41-mt acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
It's working with this:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_filesystem acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Thanks for all your help
When you link the object files to create the executable (your first makefile rule) you must pass the location of the boost libraries with the -L flag and the names of the libraries with the -l flag.
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_filesystem acctime.o bentimer.o -o accesstimer
where /usr/local/boost/boost_1_39_0/stage/lib is the directory containing the libraries and boost_filesystem the file name of the library without the beginning lib (modify those two as appropriate).
The .a file you're trying to link is the wrong one... the library should have no extension.
Hi Following is the full procedure to add boost to cmake/make file. This answer is specially developed for the novice programmer in cpp.
If you want to add the boost library support with help of Makefile you need to specify library path (with -L option) and libraries (with -l option).
-L path/to/the/libraries
-l llibrary
**Now how to find path to libraries **
Following is the trick:
Open terminal and fire command
$ locate boost > libboost.txt
$ gedit libboost.txt
This command opens a text file which contains all boost library paths.
Now find ("ctr+F") libboost, which highlights the library files of boost with extension .a and .so in this text file.
Copy the path in which this .so files are present.
eg: If .so file present as on /usr/lib/x86_64-linux-gnu/libboost_filesystem.so
then specify path as : -L /usr/lib/x86_64-linux-gnu/
Now how to find respective library?
This depends on what boost functionalities/modules you are using
for example: If you are using boost threading, you will require following libraries
libboost_filesystem.so
libboost_thread.so
libboost_system.so
Add above libraries as follows with -l option:
-l lboost_filesystem
-l lboost_thread
-l lboost_system
Hope this will helps you, further If there is more easy way, please suggest
You need to add the boost libraries to the linking phase (the accesstimer target line) and not to the compilation phase (where only the include path is needed).

Resources