Compiling Caffe: undefined reference - makefile

I'm trying to install caffe by following the instructions found here. But when compiling I get the following error:
$make all
CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
.build_release/lib/libcaffe.so: undefined reference to `_Py_Dealloc'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_FromString'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `_Py_fopen'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_AsWideChar'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_FromEncodedObject'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_AsUTF8'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_FromFormat'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `_Py_tracemalloc_config'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `_PyTraceMalloc_NewReference'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyModule_Create2'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyType_GetFlags'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyBytes_AsString'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyBytes_Size'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_AsUTF8String'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_FromStringAndSize'
/home/selma/anaconda3/lib/libboost_python.so: undefined reference to `PyUnicode_InternFromString'
collect2: error: ld returned 1 exit status
Makefile:629: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
System configuration
Operating system: Ubuntu 18.04
CUDA version : 11.0
Python : anaconda
python 3.8

Related

How to succsessfully compille .cpp files using gcc with out adding -lstdc++ flag?

The autograder of my class uses gcc to grade our projects, it only takes file uploads(.cpp .h), students can't pass in any argument flags.
My project compiles with g++ with no issues:
g++ main.cpp func1.cpp func2.cpp func1.h -o a.out
but with gcc I have to add -lstdc++ at the end for it to compile:
gcc main.cpp func1.cpp func2.cpp func1.h -o a.out -lstdc++
otherwise the errors:
/usr/bin/ld: /tmp/cck9qDRT.o: in function main': main.cpp:(.text+0x60): undefined reference to std::cout'
/usr/bin/ld: main.cpp:(.text+0x65): undefined reference to std::basic_ostream<char, std::char_traits >& std::operator<< std::char_traits<char >(std::basic_ostream<char, std::char_traits >&, char const*)' /usr/bin/ld: main.cpp:(.text+0x83): undefined reference to std::cin'
/usr/bin/ld: main.cpp:(.text+0x88): undefined reference to std::istream::operator>>(int&)' /usr/bin/ld: main.cpp:(.text+0x96): undefined reference to std::cin'
/usr/bin/ld: main.cpp:(.text+0x9b): undefined reference to std::istream::operator>>(int&)' /usr/bin/ld: main.cpp:(.text+0xb3): undefined reference to std::cout'
/usr/bin/ld: main.cpp:(.text+0xb8): undefined reference to std::ostream::operator<<(int)' /usr/bin/ld: main.cpp:(.text+0xc2): undefined reference to std::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&)'
/usr/bin/ld: main.cpp:(.text+0xcd): undefined reference to std::ostream::operator<<(std::ostream& ()(std::ostream&))' /usr/bin/ld: main.cpp:(.text+0xe5): undefined reference to std::cout'
/usr/bin/ld: main.cpp:(.text+0xea): undefined reference to std::ostream::operator<<(int)' /usr/bin/ld: main.cpp:(.text+0xf4): undefined reference to std::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&)'
/usr/bin/ld: main.cpp:(.text+0xff): undefined reference to std::ostream::operator<<(std::ostream& ()(std::ostream&))' /usr/bin/ld: /tmp/cck9qDRT.o: in function __static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x147): undefined reference to std::ios_base::Init::Init()' /usr/bin/ld: main.cpp:(.text+0x15c): undefined reference to std::ios_base::Init::~Init()'
/usr/bin/ld: /tmp/ccTpZnaT.o: in function fib1()': func1.cpp:(.text+0x31): undefined reference to std::cout'
/usr/bin/ld: func1.cpp:(.text+0x36): undefined reference to std::basic_ostream<char, std::char_traits >& std::operator<< std::char_traits<char >(std::basic_ostream<char, std::char_traits >&, char const*)' /usr/bin/ld: func1.cpp:(.text+0x40): undefined reference to std::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&)'
/usr/bin/ld: func1.cpp:(.text+0x4b): undefined reference to std::ostream::operator<<(std::ostream& ()(std::ostream&))' /usr/bin/ld: /tmp/ccTpZnaT.o: in function __static_initialization_and_destruction_0(int, int)':
func1.cpp:(.text+0x85): undefined reference to std::ios_base::Init::Init()' /usr/bin/ld: func1.cpp:(.text+0x9a): undefined reference to std::ios_base::Init::~Init()'
/usr/bin/ld: /tmp/cc2MzCjT.o: in function fib2()': func2.cpp:(.text+0x23): undefined reference to std::cout'
/usr/bin/ld: func2.cpp:(.text+0x28): undefined reference to std::basic_ostream<char, std::char_traits >& std::operator<< std::char_traits<char >(std::basic_ostream<char, std::char_traits >&, char const)' /usr/bin/ld: /tmp/cc2MzCjT.o: in function __static_initialization_and_destruction_0(int, int)':
func2.cpp:(.text+0x62): undefined reference to std::ios_base::Init::Init()' /usr/bin/ld: func2.cpp:(.text+0x77): undefined reference to std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
How do I compile using gcc without needing the -lstdc++? Does manually including all the standard libraries used on the project in code fix it?
The answer, surprisingly, is it can't be done. According to the gcc manual, the gcc command recognizes .cpp files as C++, but the use of gcc does not add the C++ library.
From your description, this sounds like a technical error in how the autograder was set up, and everyone in your class will encounter the same difficulty.
Does manually including all the standard libraries
That way lies madness. Don't even think of it.

gcc can't find the linking lldap libraries even with -Llibrary-path specified, why?

I have a smal testing program to test ldap. I tried to compile it on Ubuntu 19.04. I have the source file called myldaptest.c, I ran:
1.gcc -c myldaptest.c
2.gcc -L/usr/lib/x86_64-linux-gnu -lldap -llber -o myldaptest myldaptest.o
then the it complains:
/usr/bin/ld: ldapsearch-sync.o: in function main':
ldapsearch-sync.c:(.text.startup+0x236): undefined reference toldap_url_parse'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x30b): undefined reference to ldap_initialize'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x33a): undefined reference toldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x374): undefined reference to ldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3a3): undefined reference toldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3ea): undefined reference to ldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x422): undefined reference toldap_set_option'
...
collect2: error: ld returned 1 exit status
who can tell me why?

arm gcc linker undefined reference

I am working with this code i found on github.
In order to use the uspi library,the help documentation(USING SECTION) said that i should create a makefile and specify the includes and libraries files there.
Because i am new to makefile concept,i first try to manually do that by typing:
arm-linux-gnueabihf-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -std=c99 -I./uspi/env/include -I./uspi/include -L./uspi/lib -luspi w.o -o kernel.elf
this errors comes up:
w.o: In function `main':
w.c:(.text+0xc): undefined reference to `USPiEnvInitialize'
w.c:(.text+0x24): undefined reference to `USPiInitialize'
w.c:(.text+0x48): undefined reference to `LogWrite'
w.c:(.text+0x4c): undefined reference to `USPiEnvClose'
w.c:(.text+0x58): undefined reference to `USPiMassStorageDeviceAvailable'
w.c:(.text+0x80): undefined reference to `LogWrite'
w.c:(.text+0x84): undefined reference to `USPiEnvClose'
w.c:(.text+0xb8): undefined reference to `USPiMassStorageDeviceRead'
w.c:(.text+0xdc): undefined reference to `LogWrite'
w.c:(.text+0x108): undefined reference to `LogWrite'
w.c:(.text+0x124): undefined reference to `LogWrite'
w.c:(.text+0x13c): undefined reference to `LogWrite'
w.c:(.text+0x204): undefined reference to `LogWrite'
w.c:(.text+0x23c): undefined reference to `USPiEnvClose'
collect2: error: ld returned 1 exit status
i need the .elf file so i can generate a .img file from it
This link order:
arm-linux-gnueabihf-gcc ... -luspi w.o -o kernel.elf
is incorrect. Libraries should follow the objects they are referenced from:
arm-linux-gnueabihf-gcc ... w.o -luspi -o kernel.elf
Explanation.

Android NDK linker Error:error: undefined reference to std::basic_string

I am currently trying to build a static library of some source c++ files requiring boost. I have been following the hello-libs example and have successfully linked the boost static file dependencies as is done in the sample example.Now said that, during while building the module I get these erros :
Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'
Error:error: undefined reference to 'std::runtime_error::runtime_error(std::string const&)'
Error:error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
Error:error: undefined reference to 'std::basic_string, std::allocator >::~basic_string()'
Error:error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator const&)'
Error:error: undefined reference to 'std::runtime_error::runtime_error(std::string const&)'
Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'
Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'
Error:error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base*)'
Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'
Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'
Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'
Error:error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base const*)'
Error:error: undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'
Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'
Error:error: linker command failed with exit code 1 (use -v to see invocation)
Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'
Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'
Error:error: undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
Error:error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator const&)'
Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'
Error:error: undefined reference to 'std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
Error:Execution failed for task ':dummy:linkDummyArmeabiDebugSharedLibrary'.
A build operation failed.
Linker failed while linking libdummy.so.
See the complete log at: file:///home/cran-cg/Downloads/Hello-libs-boost/name/build/tmp/linkDummyArmeabiDebugSharedLibrary/output.txt
I had been trying to resolve this and had come upon many solutions on stackoverflow itself, suggesting that I should amend my linker path and include libc++.so library
ndk{
moduleName = 'p2psp'
stl = "c++_shared"
// ldLibs.addAll('-L'+ file("/home/cran-cg/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi").absolutePath)
ldLibs.addAll(['android', 'log','atomic'])/*"${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi",'gnustl_static'*/
toolchain = "clang"
cppFlags.add("-std=c++11")
cppFlags.add('-frtti')
cppFlags.add('-fexceptions')
cppFlags.addAll('-I' + file("/home/cran-cg/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include").absolutePath ,'-DANDROID', ' -DANDROID_NDK', '-DAWS_CUSTOM_MEMORY_MANAGEMENT', '-fPIC', '-fexceptions')
//cppFlags.add("-I${lib_distribution_root}/boost/include".toString())
//cppFlags.add("-I${file("src/main/jni/inc")}".toString())
abiFilters.addAll(['armeabi'])//, 'armeabi-v7a', 'x86'])
}
And I am confused of what should be done. Please suggest me ways as to how can I resolve this issue. Thanks :))
It looks like your boost libraries were built against gnustl (or maybe stlport), whereas you're using libc++. You can't mix and match STLs as they are not ABI compatible.
If you replace stl = "c++_shared" with stl = "gnustl_shared"(or maybe stlport_shared then it should link. Alternatively build boost against c++_shared.

undefined reference to gdImageString

I'm trying to compile a program called Contrafold and I need two libraries (libgd and libpng), the problem is a link the libraries but it through me an undefined reference error, I don't know why....My code to compile is the follow:
g++ -O3 -DNDEBUG -W -pipe -Wundef -Winline --param large-function-growth=100000 -Wall EncapsulatedPostScript.o PlotRNA.o SStruct.o Utilities.o -o plot_rna -lm -L/path-to-library/libgd.a -L/path-to-library/libpng16.a
and the errors are:
PlotRNA.cpp:(.text+0x189e): undefined reference to `gdImageString'
PlotRNA.cpp:(.text+0x1a34): undefined reference to `gdImageFilledArc'
PlotRNA.cpp:(.text+0x1a79): undefined reference to `gdImageSetAntiAliased'
PlotRNA.cpp:(.text+0x1ad6): undefined reference to `gdImageChar'
PlotRNA.cpp:(.text+0x1c76): undefined reference to `gdImageLine'
PlotRNA.cpp:(.text+0x1fce): undefined reference to `gdImageString'
PlotRNA.cpp:(.text+0x2036): undefined reference to `gdImageCreateTrueColor'
PlotRNA.cpp:(.text+0x2079): undefined reference to `gdImageColorAllocate'
PlotRNA.cpp:(.text+0x2093): undefined reference to `gdImageColorAllocate'
PlotRNA.cpp:(.text+0x213a): undefined reference to `gdImageColorAllocate'
PlotRNA.cpp:(.text+0x217d): undefined reference to `gdImageFilledRectangle'
PlotRNA.cpp:(.text+0x2182): undefined reference to `gdFontGetMediumBold'
PlotRNA.cpp:(.text+0x218f): undefined reference to `gdFontGetSmall'
PlotRNA.cpp:(.text+0x223b): undefined reference to `gdImagePng'
PlotRNA.cpp:(.text+0x2250): undefined reference to `gdImageDestroy'
Any options?
Probably you forgot to add linking with library containing gd* functions: -lgd

Resources