I'm using HDF5 for C++ on mac. I'm compiling my code with g++ -std=c++11 test.cpp. Clang is reporting the following error: clang: error: linker command failed with exit code 1 (use -v to see invocation), with additional info above it being ld: symbol(s) not found for architecture x86_64.
One of the symbol errors are as follows:
"readH5(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from: setupData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int) in test-9aa0e6.o
Would I be right in thinking there's a 32bit / 64bit dispute with the h5 library?
I'm a computer scientist, but I'm no C++ expert by any stretch, so if answers could be written for C++ beginners I would very much appreciate it.
This error is caused by improper linking at build time.
The linking library needs to be specified.
With a library, we have to tell the compiler where the header files are and then tell the linker where the libraries are located with -l.
Can you try clang++ once?
You should also try:
g++ test.cpp -o test -lhdf5 -I /usr/local/include
g++ test.cpp -o test -lhdf5 -I <hdf5 lib location>
Related
I feel that all dependences are installed, and I want to install Caffe without GPU, but when I do make all, there is an error:
CXX src/caffe/util/upgrade_proto.cpp
AR -o .build_release/lib/libcaffe.a
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolch ain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_conv_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lcn_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lrn_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_pooling_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_relu_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_sigmoid_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_softmax_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_tanh_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn.o) has no symbols
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
clang: warning: argument unused during compilation: '-pthread'
Undefined symbols for architecture x86_64:
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
caffe::WindowDataLayer<float>::load_batch(caffe::Batch<float>*) in window_data_layer.o
caffe::WindowDataLayer<double>::load_batch(caffe::Batch<double>*) in window_data_layer.o
caffe::ReadImageToCVMat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, bool) in io.o
"cv::imencode(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
caffe::ReadImageToDatum(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, caffe::Datum*) in io.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
I do not understand why this happens and it seems like my Xcode may have some problems? Could someone help me?
There are two separate things here:
"clang: warning: argument unused during compilation: '-pthread'" is an ignoreable (although annoying) compiler warning (not error) that you often get with MacOS clang, these days it has pthreads support builtin. Ignore it, or suppress it with -Wno-error=unused-command-line-argument
whereas "Undefined symbols for architecture x86_64: ... clang: error: linker command failed with exit code " is an actual error. Fix that. (Looks like a missing header file to me, so check your -I... include paths. I don't know Caffe so I can't comment more on that.)
make sure you install openCV before building caffe.
brew install -vd snappy leveldb gflags glog szip lmdb
# need the homebrew science source for OpenCV and hdf5
brew tap homebrew/science
brew install hdf5 opencv
please go threw caffe OS X Installation.
I had a similar problem as well. It could be the Makefile.config. Please check the paths you provided for PYTHON_INCLUDE and PYTHON_LIB.
I had given the brew python path to PYTHON_INCLUDE and system path to PYTHON_LIB. I also made sure that the caffe python was added to the python path before compiling.Hope this information is of help.
I'm working on a Mac. I installed libprotobuf with brew install protobuf --c++11.
17:51 $ brew info protobuf
protobuf: stable 2.6.1 (bottled), devel 3.0.0-beta-4, HEAD
Protocol buffers (Google's data interchange format)
https://github.com/google/protobuf/
/usr/local/Cellar/protobuf/2.6.1 (149 files, 7.0M) *
Built from source on 2016-08-02 at 17:42:15 with: --c++11
libprotobuf.dylib lives in /usr/local/Cellar/protobuf/2.6.1/lib.
I wrote the following dummy app hoping to invoke this constructor:
// test.cc
#include <string>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
int main() {
std::string s{"hello"};
google::protobuf::io::StringOutputStream sos(&s);
}
When I compile the app, I get an undefined reference error:
17:55 $ g++ -L/usr/local/Cellar/protobuf/2.6.1/lib -std=c++14 test.cc -lprotobuf
Undefined symbols for architecture x86_64:
"google::protobuf::io::StringOutputStream::StringOutputStream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)", referenced from:
_main in ccyQlDM5.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
When I check the .dylib for StringOutputStream, it's a little wonky.
17:56 $ nm /usr/local/Cellar/protobuf/2.6.1/lib/libprotobuf.dylib | c++filt | grep "StringOutputStream(std::"
000000000000e3ac T google::protobuf::io::StringOutputStream::StringOutputStream(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
000000000000e398 T google::protobuf::io::StringOutputStream::StringOutputStream(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
Why is basic_string namespace-prefixed by ::__1 in my list of symbols for that .dylib? How can I fix this?
If this isn't a problem (perhaps an artifact of unmangling), why am I still receiving an undefined reference to a constructor call I know to be defined?
I'm using gcc 5.3.0 to compile test.cc.
As referenced in the comments, Homebrew was building with clang instead of g++.
I removed the protobuf installed by brew, checked out and built the source, copied the new .dylib to /usr/local/lib and it worked fine.
I am a beginner in programming and compiling C++. I am currently trying to build a very basic OGRE application on OSX (10.10) using g++ compiler and makefile. My makefile is based on the one provided on cleversoap's github repository. I am also using a prebuilt version of the SDK for OSX.
When I first tried to build the tutorial framework from the OGRE 3D webiste, I ended up with multiple linking errors related to the Ogre objects and functions definitions. I edited the source file leaving only those few lines of code.
#include <OgreRoot.h>
#include <OgreCamera.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreLogManager.h>
#include <OgreViewport.h>
#include <OgreEntity.h>
#include <OgreWindowEventUtilities.h>
#include <OgrePlugin.h>
int main() {
Ogre::Root* mRoot;
mRoot = new Ogre::Root("", "", "LowLevelOgre.log");
delete mRoot;
}
My compile command resulting of the makefile looks like this:
g++ LowLevelOgre.cpp -o OgreMake.app/Contents/MacOS/OgreMake -arch i386 -I/Developer/SDKs/OgreSDK/include/OGRE -I/Developer/SDKs/OgreSDK/include/OGRE/OSX -I/Developer/SDKs/OgreSDK/include/OIS -I/Developer/SDKs/OgreSDK/boost -L/Developer/SDKs/OgreSDK/lib/release -lOIS -F/System/Library/Frameworks -F/Library/Frameworks -framework Carbon -framework AppKit -framework Foundation -framework IOKit -F/Developer/SDKs/OgreSDK/lib/release -framework Cg -framework Ogre
Even though the linker does not complain about the Ogre.framework, I get this error basically meaning that the Ogre::Root definition is missing. (At least I think)
Undefined symbols for architecture x86_64:
"Ogre::Root::Root(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in main-3183b9.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
I cannot seem to find what is causing this linking error. Is there anything I am missing or I may have misunderstood?
I understand what an unresolved symbol error is, but I don't understand why I'm getting it in this particular situation with this particular library. Here is the output of the error.
Undefined symbols for architecture x86_64:
"soci::soci_error::soci_error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
soci::type_conversion<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::from_base(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, soci::indicator, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in Inspector.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Note that I am using the following link flags:
-L/usr/local/lib -lsoci_core -lsoci_postgresql -lpq -ldl
Note also that references to other symbols (e.g., the soci::session constructor and destructor) are being resolved.
What am I doing wrong? Is there another soci library that I should also be linking against?
EDIT: Note that I am working on Mac OS X, and have tried both the installation through homebrew (via brew install soci --with-pg), and the standalone installations of 3.2.2 and 3.2.1.
I don't know why this solved the error, but changing from libc++ to libstdc++ resolved it.
I'm trying to compile the Sam Hare's Struck code.
I'm using mac OSX10.9, opencv 2.4.6 and Eigen 2.0.17.
Eigen and opencv headers are stored in /opt/local/include while opencv dylib in /opt/local/lib.
I modified the Hare's Makefile to work on this folder. When I type make on the terminal:
g++ -L/opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc src/Config.o src/Features.o src/HaarFeature.o src/HaarFeatures.o src/HistogramFeatures.o src/ImageRep.o src/LaRank.o src/MultiFeatures.o src/RawFeatures.o src/Sampler.o src/Tracker.o src/main.o src/GraphUtils/GraphUtils.o -o struck
I get these errors:
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
int)", referenced from:
_main in main.o "cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)",
referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o "cv::imread(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
int)", referenced from:
_main in main.o "cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&,
cv::_InputArray const&)", referenced from:
LaRank::Debug() in LaRank.o
Tracker::Debug() in Tracker.o
_main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Any ideas? Thanks!
I had a similar warning/error/failure when I was simply trying to make an executable from two different object files (main.o and add.o). I was using the command:
gcc -o exec main.o add.o
But my program is a C++ program. Using the g++ compiler solved my issue:
g++ -o exec main.o add.o
I was always under the impression that gcc could figure these things out on its own. Apparently not. I hope this helps someone else searching for this error.
finally solved my problem.
I created a new project in XCode with the sources and changed the C++ Standard Library from the default libc++ to libstdc++ as in this and this.
I am getting the same error. I don't think it is a "fix", but my work-around is to also include the cpp file. So instead of just putting
#include "MyClass.h"
I have to put
#include "MyClass.h"
#include "MyClass.cpp"
I wrote my declarition in the .h file
class String
{
String (const char * cstr = 0);
};
and I used inline in another .cpp file (implementation)
inline String::String(const char * cstr)
{
//code ...
}
then I use g++ and get this:
Undefined symbols for architecture x86_64:
"String::String(char const*)", referenced from:
_main in test-d389f3.o
ld: symbol(s) not found for architecture x86_64
solution: do not write inline when declarition and implementation is independent.
When I using clang to compile a C++ program, I have the similar error.
But after I changing to use chang++, the compilation worked.