g++ compilation undefined references on external hpp file - c++

I am trying to include pugixml.hpp in my code using the following include notation :
#include "pugixml-1.7/src/pugixml.hpp"
Now the weird thing is, this runs in Codeblocks fine, but when I am trying to run it via terminal (I have all the source codes in one single file) using g++ :
g++-5 -v -std=c++11 -03 -Wall -pedantic -fopenmp -pthread main.cpp -o main.o
It throws out a bunch of undefined reference to pugi::xml.. (whichever the api I was using). I have tried everything, by keeping the pugixml.hpp file in the main directory, by adding bunch of flags like -iquote or -c to point to that directory.. but nothing is working. What else I should try? I am including the output till directory search here :
Using built-in specs.
COLLECT_GCC=g++-5
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.2.1-23ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=gcc4-compatible --disable-libstdcxx-dual-abi --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.2.1 20151031 (Ubuntu 5.2.1-23ubuntu1~12.04)
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-O3' '-Wall' '-Wpedantic' '-fopenmp' '-pthread' '-o' 'main.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
/usr/lib/gcc/x86_64-linux-gnu/5/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D_REENTRANT main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -O3 -Wall -Wpedantic -std=c++11 -version -fopenmp -fstack-protector -Wformat-security -o /tmp/ccXfMWIT.s
GNU C++11 (Ubuntu 5.2.1-23ubuntu1~12.04) version 5.2.1 20151031 (x86_64-linux-gnu)
compiled by GNU C version 5.2.1 20151031, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/5"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/5
/usr/include/x86_64-linux-gnu/c++/5
/usr/include/c++/5/backward
/usr/lib/gcc/x86_64-linux-gnu/5/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.

You need to link against the compiled pugixml library. Including the pugixml.hpp is simply telling the preprocessor to get the interface, however the compiler (more specifically the linker) needs to find the appropriate compiled pugixml code for it to be usable from your source code.

Related

/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No such file or directory

I'm a beginner in linux and when I was running my first program "HELLOWORLD" on my raspberry pi this warning appeared:
pi#raspberrypi:~/raspitest $ g++ test.cpp -o test
In file included from /usr/include/c++/8/ext/string_conversions.h:41,
from /usr/include/c++/8/bits/basic_string.h:6400,
from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from test.cpp:1:
/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
I was not using any make tools, just wrote the code via vim and ran the following command:
pi#raspberrypi:~/raspitest $ g++ test.cpp -o test
The stdlib.h should have been in the right path:
pi#raspberrypi:~/raspitest $ locate stdlib.h
/opt/Wolfram/WolframEngine/12.1/SystemFiles/Links/ArduinoLink/Resources/CSource/avr-libc/1.8.1/avr/include/stdlib.h
/usr/include/stdlib.h
/usr/include/arm-linux-gnueabihf/bits/stdlib.h
/usr/include/c++/8/stdlib.h
/usr/include/c++/8/tr1/stdlib.h
/usr/include/freetype2/freetype/config/ftstdlib.h
here are my original code:
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
cout <<"hello,world" << endl;
return 0;
}
and here is the output of g++ -v test.cpp:
pi#raspberrypi:~/raspitest $ g++ -v test.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/8/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 8.3.0-6+rpi1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mfloat-abi=hard' '-mfpu=vfp' '-mtls-dialect=gnu' '-marm' '-march=armv6+fp'
/usr/lib/gcc/arm-linux-gnueabihf/8/cc1plus -quiet -v -imultilib . -imultiarch arm-linux-gnueabihf -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mfloat-abi=hard -mfpu=vfp -mtls-dialect=gnu -marm -march=armv6+fp -auxbase test -version -o /tmp/cchrh8l9.s
GNU C++14 (Raspbian 8.3.0-6+rpi1) version 8.3.0 (arm-linux-gnueabihf)
compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/arm-linux-gnueabihf/c++/8"
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory "/usr/lib/gcc/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/include"
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include
/usr/include/c++/8
/usr/include/arm-linux-gnueabihf/c++/8
/usr/include/c++/8/backward
/usr/lib/gcc/arm-linux-gnueabihf/8/include
/usr/local/include
/usr/lib/gcc/arm-linux-gnueabihf/8/include-fixed
/usr/include/arm-linux-gnueabihf
End of search list.
GNU C++14 (Raspbian 8.3.0-6+rpi1) version 8.3.0 (arm-linux-gnueabihf)
compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7defdc925cf5fede452fc531d54623d1
In file included from /usr/include/c++/8/ext/string_conversions.h:41,
from /usr/include/c++/8/bits/basic_string.h:6400,
from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from test.cpp:1:
/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: 没有那个文件或目录
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
Thanks for the hints from the comments. Here is my soloution:
add
export CPLUS_INCLUDE_PATH=/usr/include/c++/8:$CPLUS_INCLUDE_PATH
to ~/.bashrcfile. If still not working, try to reboot or copy all the headfiles to a new folder and change the cplus_path again.

Linking error in test program with RTP (Real-Time Transport Protocol) [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 2 years ago.
I am trying to compile a simple test program using rtp (Real-Time Transport Protocol). Unfortunately I get a linking error I can not get rid off. Here is the Code i try to compile with:
g++ -v main.cpp -o rtp -lccrtp
Here is the main.cpp
#include <ccrtp/rtp.h>
int main(int argc, char *argv[])
{
ost::RTPSession s(ost::InetHostAddress("127.0.0.1"),9000); // bind reception socket.
return 0;
}
and the output:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)
COLLECT_GCC_OPTIONS='-v' '-o' 'rtp' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/8/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -version -o /tmp/ccMnYiXi.s
GNU C++14 (Debian 8.3.0-6) version 8.3.0 (x86_64-linux-gnu)
compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/8"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/8
/usr/include/x86_64-linux-gnu/c++/8
/usr/include/c++/8/backward
/usr/lib/gcc/x86_64-linux-gnu/8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/8/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++14 (Debian 8.3.0-6) version 8.3.0 (x86_64-linux-gnu)
compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3c854693d01dc9a844a56a0b1ab1c0f4
COLLECT_GCC_OPTIONS='-v' '-o' 'rtp' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/ccBl5GBx.o /tmp/ccMnYiXi.s
GNU assembler version 2.31.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.31.1
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'rtp' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/8/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/8/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper -plugin-opt=-fresolution=/tmp/cc36T3hM.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -o rtp /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/8/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/8 -L/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/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/8/../../.. /tmp/ccBl5GBx.o -lccrtp -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/8/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld: /tmp/ccBl5GBx.o: undefined reference to symbol '_ZNK7ucommon14JoinableThread9is_activeEv'
/usr/bin/ld: //lib/x86_64-linux-gnu/libucommon.so.8: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Thanks for the help.
Thanks for the fast reply. That directed me to the solution. I also needed to install
libcommoncpp2-dev
and now it compiles with:
g++ -lccrtp -lucommon -lcommoncpp -o rtp main.cpp
without any errors. Thanks again.

Runtime "symbol lookup error" after compilation and linking of .so

first of all I've searched this one quite a bit and haven't managed to find a question with the same situation.
I'm building a 32 bit plugin as a shared-object on a 64 bit machine and using cpp-redis. cpp-redis built fine and I used a cmake toolchain to force 32 bit, checked the .o files during build and confirmed they are 32 bit.
I compiled and linked my very basic program (consisting of one main source file and an extra lib for talking to my host application since this is a plugin).
Upon running loading the plugin into the host app, I am greeted with:
symbol lookup error: plugins/samp-redis.so: undefined symbol: _ZN9cpp_redis16redis_subscriberC1ERKSt10shared_ptrINS_7network10io_serviceEE
I'm pretty stumped as I've added the cpp-redis dir to the linker path with -L and the library with -l, here's my comp/link lines:
(SDK_DIR is my host app sdk, pretty small and minimal set of .c/h files)
g++ -fpermissive -fPIC -m32 -std=c++11 -c -O3 -w -D LINUX -I$(SDK_DIR) -I$(SDK_DIR)/amx -I/usr/local/include/cpp_redis (source .cpp files...)
g++ -v -Wall -O2 -m32 -fshort-wchar -s -shared -L/usr/local/lib/ -lcpp_redis -o $(OUTFILE) *.o
Which runs fine with no errors, I ran the link stage with -v to check the flags went in properly and it all looks fine.
(added some newlines for readability)
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure
-v
--with-pkgversion='Debian 4.9.2-10'
--with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++
--prefix=/usr
--program-suffix=-4.9
--enable-shared
--enable-linker-build-id
--libexecdir=/usr/lib
--without-included-gettext
--enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.9
--libdir=/usr/lib
--enable-nls
--with-sysroot=/
--enable-clocale=gnu
--enable-libstdcxx-debug
--enable-libstdcxx-time=yes
--enable-gnu-unique-object
--disable-vtable-verify
--enable-plugin
--with-system-zlib
--disable-browser-plugin
--enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre
--enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64
--with-arch-directory=amd64
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc
--enable-multiarch
--with-arch-32=i586
--with-abi=m64
--with-multilib-list=m32,m64,mx32
--enable-multilib
--with-tune=generic
--enable-checking=release
--build=x86_64-linux-gnu
--host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.2 (Debian 4.9.2-10)
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.9/32/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32/
:/lib/../lib32/
:/usr/lib/../lib32/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../
:/lib/
:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-Wall' '-O2' '-m32' '-fshort-wchar' '-s' '-shared' '-L/usr/local/lib/' '-o' 'samp-redis.so' '-shared-libgcc' '-mtune=generic' '-march=i586'
/usr/lib/gcc/x86_64-linux-gnu/4.9/collect2
-plugin /usr/lib/gcc/x86_64-linux-gnu/4.9/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
-plugin-opt=-fresolution=/tmp/cc0Lo5po.res
-plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s
--sysroot=/
--build-id
--eh-frame-hdr
-m elf_i386
--hash-style=gnu
-shared
-o samp-redis.so
-s /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.9/32/crtbeginS.o
-L/usr/local/lib/
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/32
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32
-L/lib/../lib32
-L/usr/lib/../lib32
-L/usr/lib/gcc/x86_64-linux-gnu/4.9
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../..
-lcpp_redis amxplugin2.o amxplugin.o main.o
-lstdc++
-lm
-lgcc_s
-lc
-lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.9/32/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32/crtn.o
Am I misunderstanding the linking stage or statically linking? It has been a while since I did C++... I'm all about Python and Go these days!
EDIT:
Compiling with -W,--no-undefined results in this output:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure
-v
--with-pkgversion='Debian 4.9.2-10'
--with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++
--prefix=/usr
--program-suffix=-4.9
--enable-shared
--enable-linker-build-id
--libexecdir=/usr/lib
--without-included-gettext
--enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.9
--libdir=/usr/lib
--enable-nls
--with-sysroot=/
--enable-clocale=gnu
--enable-libstdcxx-debug
--enable-libstdcxx-time=yes
--enable-gnu-unique-object
--disable-vtable-verify
--enable-plugin
--with-system-zlib
--disable-browser-plugin
--enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre
--enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64
--with-arch-directory=amd64
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc
--enable-multiarch
--with-arch-32=i586
--with-abi=m64
--with-multilib-list=m32,m64,mx32
--enable-multilib
--with-tune=generic
--enable-checking=release
--build=x86_64-linux-gnu
--host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.2 (Debian 4.9.2-10)
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.9/32/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32/
:/lib/../lib32/
:/usr/lib/../lib32/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/
:/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../
:/lib/
:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-Wall' '-O2' '-m32' '-fshort-wchar' '-s' '-shared' '-L/usr/local/lib/' '-o' 'samp-redis.so' '-shared-libgcc' '-mtune=generic' '-march=i586'
/usr/lib/gcc/x86_64-linux-gnu/4.9/collect2
-plugin /usr/lib/gcc/x86_64-linux-gnu/4.9/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccOq8qY8.res
-plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s
--sysroot=/
--build-id
--eh-frame-hdr
-m elf_i386
--hash-style=gnu
-shared
-o samp-redis.so
-s /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.9/32/crtbeginS.o
-L/usr/local/lib/
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/32
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32
-L/lib/../lib32
-L/usr/lib/../lib32
-L/usr/lib/gcc/x86_64-linux-gnu/4.9
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../..
-Bstatic
--no-undefined
-lcpp_redis amxplugin.o amxplugin2.o main.o
-lstdc++
-lm
-lgcc_s
-lc
-lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.9/32/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib32/crtn.o
/usr/bin/ld: cannot find
-lgcc_s
/usr/bin/ld: cannot find
-lgcc_s
collect2: error: ld returned 1 exit status
makefile:15: recipe for target 'build' failed
make: *** [build] Error 1
Apparently it can't find gcc_s whatever that is? s=static?
I tried searching for gcc libs:
$ find /usr/ -name libgcc*
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/4.9/x32/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/4.9/x32/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/4.9/x32/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/4.9/32/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/4.9/32/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/4.9/32/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_s_32.so
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_s_x32.so
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a
/usr/lib/x86_64-linux-gnu/libgccpp.so.1
/usr/lib/x86_64-linux-gnu/libgccpp.so.1.0.3
Yet doing a ldconfig search shows files named libgcc.so.1:
$ sudo /sbin/ldconfig -p | grep libgcc
libgccpp.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgccpp.so.1
libgcc_s.so.1 (libc6,x32) => /usr/libx32/libgcc_s.so.1
libgcc_s.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libgcc_s.so.1
libgcc_s.so.1 (libc6) => /usr/lib32/libgcc_s.so.1
Could this be the reason?
And googling the error brings up some results so I'll keep digging...
Even if you build cpp_redis as static library for it to be linkable with shared library it must be compiled with -fPIC flag ie code must be relocatable. Looks like in your case linker silently ignores incompatible code when linking shared lib. You can check if symbols from cpp_redis resolved into your plugin by running nm with your .so file.
According to your update, you should link your plugin with -W,--no-undefined not cpp_redis. Most probably it will fail as symbols from host program would be missing. But you can check if symbols from cpp_redis are listed as missing or not.

Compilation error after including <map>

I just started with C++, trying to learn some basics. Right now compiling using gcc version 5.2.1 in Eclipse, project is compiled with c++11 parameter.
Now the include problem occurs when I try to #include <map> (it doesn't really matter where as long as compiler gets into it, I don't even use map yet, just trying to include it). As far as I can understand there's a problem with map itself, but it doesn't seem right. Short failure snippet here.
08:54:59 **** Incremental Build of configuration Debug for project RpnCalculator ****
make all
Building file: ../Test/AddShouldBeRegistered.cpp
Invoking: Cross G++ Compiler
g++ -I/home/yoger/Coding/cpputest/include -O0 -g3 -Wall -c -fmessage- length=0 -std=c++11 -v -MMD -MP -MF"Test/AddShouldBeRegistered.d" -MT"Test/AddShouldBeRegistered.d" -o "Test/AddShouldBeRegistered.o" "../Test/AddShouldBeRegistered.cpp"
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.2.1-22ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2)
COLLECT_GCC_OPTIONS='-I' '/home/yoger/Coding/cpputest/include' '-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-std=c++11' '-v' '-MMD' '-MP' '-MF' 'Test/AddShouldBeRegistered.d' '-MT' 'Test/AddShouldBeRegistered.d' '-o' 'Test/AddShouldBeRegistered.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/5/cc1plus -quiet -v -I /home/yoger/Coding/cpputest/include -imultiarch x86_64-linux-gnu -MMD Test/AddShouldBeRegistered.d -MF Test/AddShouldBeRegistered.d -MP -MT Test/AddShouldBeRegistered.d -dD -D_GNU_SOURCE ../Test/AddShouldBeRegistered.cpp -quiet -dumpbase AddShouldBeRegistered.cpp -mtune=generic -march=x86-64 -auxbase-strip Test/AddShouldBeRegistered.o -g3 -O0 -Wall -std=c++11 -version -fmessage-length=0 -fstack-protector-strong -Wformat-security -o /tmp/cc8xNfBA.s
GNU C++11 (Ubuntu 5.2.1-22ubuntu2) version 5.2.1 20151010 (x86_64-linux-gnu)
compiled by GNU C version 5.2.1 20151010, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/5"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/home/yoger/Coding/cpputest/include
/usr/include/c++/5
/usr/include/x86_64-linux-gnu/c++/5
/usr/include/c++/5/backward
/usr/lib/gcc/x86_64-linux-gnu/5/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++11 (Ubuntu 5.2.1-22ubuntu2) version 5.2.1 20151010 (x86_64-linux-gnu)
compiled by GNU C version 5.2.1 20151010, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5ed623d6fe11f4bcc1afee70f77e33b0
In file included from /usr/include/c++/5/map:60:0,
from ../Test/../MathOperations/MathOperationFactory.h:11,
from ../Test/ShouldBeRegistered.h:13,
from ../Test/AddShouldBeRegistered.cpp:9:
/usr/include/c++/5/bits/stl_tree.h: In member function ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type, _Args&& ...)’:
/usr/include/c++/5/bits/stl_tree.h:528:14: error: ‘__node’ does not name a type
::new(__node) _Rb_tree_node<_Val>;
^
Test/subdir.mk:66: recipe for target 'Test/AddShouldBeRegistered.o' failed
make: *** [Test/AddShouldBeRegistered.o] Error 1
08:54:59 Build Finished (took 361ms)
Alright, the file where I include map
#ifndef MATHOPERATIONFACTORY_H_
#define MATHOPERATIONFACTORY_H_
#include <map>
#include <string>
class MathOperation;
class MathOperationFactory {
public:
MathOperationFactory();
virtual ~MathOperationFactory();
virtual MathOperation& findOperationNamed(const std::string &name);
private:
typedef std::map<std::string, MathOperation*> OperationMap;
typedef OperationMap::iterator iterator;
OperationMap _operationsByName;
};
#endif
It's a problem related with memory leak detection feature of Cpputest. You can apply one of the solutions described in documentation page of Cpputest.
http://cpputest.github.io/manual.html#memory_leak_detection
I am able to avoid this issue by making sure that <map> is included before any CppUTest related includes.
example:
class1.h:
#include <map>
.
.
//your code for class 1 business logic
class1_test.cpp:
#include "class1.h"
//other include
#include <CppUTest/TestHarness.h> // at very end
Follow this rule in places wherever you are going to include CppUtest header
So I didn't find exact answer but managed to completely fix the issue by simply moving all project files to new project.
That means that problem was somehow related to project settings, I compared compiler settings for both projects, they were the same so the reason is still covered with very fine layer of diamond hard mist.

unable to link Intel TBB library with libtbb in /usr/lib

I downloaded the pre built headers and libraries for Intel TBB from Intel's TBB website. I updated ldconfig to add the tbb shared library to /usr/lib. However on compiling with -tbb the code using g++ ld returns -1 as it is unable to find libtbb
libtbb.so.2 is present in /usr/lib/
here is my full g++ output
g++ hellotbb.cpp -o htbb -I$HOME/libs/tbb43/include -v -ltbb
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
COLLECT_GCC_OPTIONS='-o' 'htbb' '-I' '/home/govind/libs/tbb43/include' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -quiet -v -I /home/govind/libs/tbb43/include -imultiarch x86_64-linux-gnu -D_GNU_SOURCE hellotbb.cpp -quiet -dumpbase hellotbb.cpp -mtune=generic -march=x86-64 -auxbase hellotbb -version -fstack-protector -Wformat -Wformat-security -o /tmp/ccnjmEt3.s
GNU C++ (Ubuntu 4.8.2-19ubuntu1) version 4.8.2 (x86_64-linux-gnu)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.8"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/home/govind/libs/tbb43/include
/usr/include/c++/4.8
/usr/include/x86_64-linux-gnu/c++/4.8
/usr/include/c++/4.8/backward
/usr/lib/gcc/x86_64-linux-gnu/4.8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++ (Ubuntu 4.8.2-19ubuntu1) version 4.8.2 (x86_64-linux-gnu)
compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 26a7c0bd346d04102f6aea776e0cccc5
COLLECT_GCC_OPTIONS='-o' 'htbb' '-I' '/home/govind/libs/tbb43/include' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
as -v -I /home/govind/libs/tbb43/include --64 -o /tmp/ccC9Xpee.o /tmp/ccnjmEt3.s
GNU assembler version 2.24 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' 'htbb' '-I' '/home/govind/libs/tbb43/include' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.8/collect2 --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o htbb /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/crtbegin.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/ccC9Xpee.o -ltbb -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /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
/usr/bin/ld: cannot find -ltbb
collect2: error: ld returned 1 exit status
It seems that ld does not detect my tbb library in /usr/lib/
Make sure libtbb.so is also present and install libtbb-dev package if needed:
apt-get install libtbb-dev
BTW, your include files are located in suspicious place. Looks like you mixed installation of TBB binaries and include files from different sources. It can lead to bad problems especially if headers are newer than binaries.