I'm trying to compile a caffe classification example on OS X 10.10.5, with the following command:
g++ -ggdb `pkg-config --cflags --libs opencv` -I /Users/SullyChen/caffe/include -I /usr/local/cuda/include -I /usr/local/Cellar/openblas/0.2.15/include -lboost_system -lglog -lprotobuf classification.cpp -o classification
But I get the following error:
Undefined symbols for architecture x86_64:
"caffe::ReadProtoFromBinaryFile(char const*, google::protobuf::Message*)", referenced from:
caffe::ReadProtoFromBinaryFileOrDie(char const*, google::protobuf::Message*) in classification-ff6167.o
"caffe::Net<float>::CopyTrainedLayersFrom(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
Classifier::Classifier(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&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in classification-ff6167.o
"caffe::Net<float>::Forward(float*)", referenced from:
Classifier::Predict(cv::Mat const&) in classification-ff6167.o
"caffe::Net<float>::Reshape()", referenced from:
Classifier::Predict(cv::Mat const&) in classification-ff6167.o
"caffe::Net<float>::Net(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, caffe::Phase, caffe::Net<float> const*)", referenced from:
Classifier::Classifier(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&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in classification-ff6167.o
"caffe::Blob<float>::mutable_cpu_data()", referenced from:
Classifier::SetMean(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in classification-ff6167.o
Classifier::WrapInputLayer(std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >*) in classification-ff6167.o
"caffe::Blob<float>::Reshape(int, int, int, int)", referenced from:
Classifier::Predict(cv::Mat const&) in classification-ff6167.o
"caffe::Blob<float>::FromProto(caffe::BlobProto const&, bool)", referenced from:
Classifier::SetMean(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in classification-ff6167.o
"caffe::Caffe::Get()", referenced from:
caffe::Caffe::set_mode(caffe::Caffe::Brew) in classification-ff6167.o
"caffe::BlobProto::BlobProto()", referenced from:
Classifier::SetMean(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in classification-ff6167.o
"caffe::BlobProto::~BlobProto()", referenced from:
Classifier::SetMean(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in classification-ff6167.o
"caffe::Blob<float>::cpu_data() const", referenced from:
Classifier::Predict(cv::Mat const&) in classification-ff6167.o
Classifier::Preprocess(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >*) in classification-ff6167.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 on what the problem is?
Oh my goodness I forgot to link Caffe... Well that problem is solved.
Edit: Here is the command I used in case anyone needs it
g++ -ggdb `pkg-config --cflags --libs opencv` -I /Users/SullyChen/caffe/include -I /usr/local/cuda/include -I /usr/local/Cellar/openblas/0.2.15/include -lboost_system -lglog -lprotobuf -L /Users/SullyChen/caffe/.build_release/lib -lcaffe classification.cpp -o classification
Related
I recently started a project using swift and c++. So I installed Xcode and started using it. I first encountered some bugs, but fixed theme.
However, I still got some Undefined symbols for architecture x86_64:
I searched online and I can't find the solution for my problem (otherwise I would not have asked the question).
This is the whole error :
"parser(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, Node*, int, int)", referenced from:
utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
"recognize_paternes(Node*, bool)", referenced from:
utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
"ast_t_rep(Node*, int)", referenced from:
utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
"lex(char const*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&)", referenced from:
utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
"visitor(std::__1::vector<Node*, std::__1::allocator<Node*> >, bool, bool, bool)", referenced from:
utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) 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)
But I think we can just consider :
utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
as this error seems to be redundant.
In my main.cpp file, I imported the header file (parser.h) where I declared Node *parser(vector<string>, Node *, int, int);.
In main.cpp>utilise_file(...), I call the function parser:
void utilise_file(){
...
vector<string> code_ref = vector<string>();
vector<string> lexeme = lex(source.c_str(), code_ref);
Node *ast_t = new Node();
ast_t->value = "main";
ast_t->type = "root";
Node *p = parser(lexeme, ast_t, 0, int(lexeme.size()));
...
}
So normally, I would not get this error.
It seems to me that it is a 'type' sort of problem, but I can't figure what.
I searched online for solutions, and I tried adding -Xlinker in Xcode>Linking>Other Liner Flags, but it didn't helped.
I also thought of adding the flags linking to the header in the compiling command line, but I think Xcode does that automatically. (Or not because many of my headers are not recognized in the file arborescence...)
Thank you for your help ;)
Edit : I found the problem, I had to manually add the previously written header files in Xcode (which did not do it automatically).
I found the problem.
When I imported the previously written header files in Xcode, Xcode did not attached them to the project.
I had to manually add theme, and now it works fine !
I need to write a piece of cpp code that will read a trajectory file (.pdb or .dcd files). I have followed the steps on the homepage of chemfiles library to read in the file. I am getting an error about undefined symbols for architecture x86_64 (please see a piece of the error log below).
What I want: Able to read the .dcd/.pdb file using the chemfiles library (or any other suitable library to do so) - I need to access the coordinates of the atoms listed in the file.
Code that reproduces the error when compiled using the command below:
#include "/usr/local/include/chemfiles.hpp" //path to library on my mac
int main(int argc, char *argv[]) {
chemfiles::Trajectory testfile("test.dcd");
return 1;
}
Code that compiles successfully in CLI using the command below:
#include "/usr/local/include/chemfiles.hpp" //path to library on my mac
int main(int argc, char *argv[]) {
// chemfiles::Trajectory testfile("test.dcd");
return 1;
}
Command to compile program:
g++-8 -fopenmp trial.cpp -o trial -lchemfiles -L /usr/local/lib
// I am using openmp because my original code is about parallelisation with openmp
Error:
Undefined symbols for architecture x86_64:
"chemfiles::Trajectory::Trajectory(std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >, char,
std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)", referenced from:
_main in ccnk7agz.o
"std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::find(char, unsigned long) const",
referenced from:
file_open_info::parse(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&) in libchemfiles.a(Trajectory.cpp.o)
split_comment(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >&) in
libchemfiles.a(LAMMPSData.cpp.o)
"std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::rfind(char, unsigned long) const",
referenced from:
file_open_info::parse(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&) in libchemfiles.a(Trajectory.cpp.o)
chemfiles::SDFFormat::read(chemfiles::Frame&) in
libchemfiles.a(SDF.cpp.o)
"std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::compare(unsigned long, unsigned long, char
const*, unsigned long) const", referenced from:
file_open_info::parse(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&) in libchemfiles.a(Trajectory.cpp.o)
chemfiles::Trajectory::Trajectory(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >, char,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> > const&) in libchemfiles.a(Trajectory.cpp.o)
chemfiles::FormatFactory::register_format(chemfiles::FormatInfo,
std::__1::function<std::__1::unique_ptr<chemfiles::Format,
std::__1::default_delete<chemfiles::Format> >
(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, chemfiles::File::Mode,
chemfiles::File::Compression)>) in libchemfiles.a(FormatFactory.cpp.o)
chemfiles::Frame::guess_bonds() in
libchemfiles.a(Frame.cpp.o)
chemfiles::FormatInfo::FormatInfo(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >) in
libchemfiles.a(CSSR.cpp.o)
chemfiles::FormatInfo::FormatInfo(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >) in
libchemfiles.a(MMTF.cpp.o)
chemfiles::MOL2Format::read(chemfiles::Frame&) in
libchemfiles.a(MOL2.cpp.o)
...
I have been following many other answers here on StackOverflow and other resources, but I can't get clang to work with boost 1.63 on macOS. Simply installed boost:
./bootstrap.sh --prefix=/usr/local
./b2 cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
Now. Im just doing the following:
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main()
{
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;
}
This gives me:
clang++ \
-g -Wall -Wextra \
-std=c++14 \
-stdlib=libc++ \
-I /usr/local/include \
-L /usr/local/lib \
./src/main.cpp \
-o ./src/tool.o
Undefined symbols for architecture x86_64:
"boost::program_options::validators::check_first_occurrence(boost::any const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, int*, long) in main-afe96c.o
"boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)", referenced from:
boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, 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&, int) in main-afe96c.o
"boost::program_options::options_description::add_options()", referenced from:
_main in main-afe96c.o
"boost::program_options::options_description::m_default_line_length", referenced from:
_main in main-afe96c.o
"boost::program_options::options_description::options_description(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, unsigned int)", referenced from:
_main in main-afe96c.o
"boost::program_options::invalid_option_value::invalid_option_value(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::vector<int, std::__1::allocator<int> >*, int) in main-afe96c.o
void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, int*, long) in main-afe96c.o
"boost::program_options::error_with_option_name::error_with_option_name(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&, int)", referenced from:
boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, 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&, int) in main-afe96c.o
"boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)", referenced from:
_main in main-afe96c.o
"boost::program_options::options_description_easy_init::operator()(char const*, char const*)", referenced from:
_main in main-afe96c.o
"boost::program_options::arg", referenced from:
boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char>::name() const in main-afe96c.o
"boost::program_options::error_with_option_name::substitute_placeholders(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in main-afe96c.o
vtable for boost::program_options::validation_error in main-afe96c.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in main-afe96c.o
vtable for boost::program_options::invalid_option_value in main-afe96c.o
"boost::program_options::error_with_option_name::what() const", referenced from:
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in main-afe96c.o
vtable for boost::program_options::validation_error in main-afe96c.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in main-afe96c.o
vtable for boost::program_options::invalid_option_value in main-afe96c.o
"boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool) const", referenced from:
vtable for boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char> in main-afe96c.o
"typeinfo for boost::program_options::error_with_option_name", referenced from:
typeinfo for boost::program_options::validation_error in main-afe96c.o
"typeinfo for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
typeinfo for boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char> in main-afe96c.o
"vtable for boost::program_options::error_with_option_name", referenced from:
boost::program_options::error_with_option_name::error_with_option_name(boost::program_options::error_with_option_name const&) in main-afe96c.o
boost::program_options::error_with_option_name::~error_with_option_name() in main-afe96c.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper() in main-afe96c.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [annorna] Error 1
However, adding -l boost_system does not work. What is the solution to get boost going? Is the path wrong? OR do I need some other flag?
I'm trying to compile some C++ code (including C++11 features) on OS X 10.8 using the clang++ compiler. I have a makefile that generates the object files OK, then on the command:
clang++ -o Analysis.so -shared DataFile.o CR39DataFile.o
I get tons of errors about symbol(s) not found for architecture x86_64. The code works fine on a *nix system using g++ and changing the compiler flags appropriately for C++11 support. To compile the *.o I am doing it like:
clang++ -c -Wall -std=c++11 -stdlib=libc++ -I../src ../src/DataFile.cc
Edit: output of the linking command is:
clang++ -o Analysis.so -shared DataFile.o CR39DataFile.o
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char const*, unsigned long, unsigned long) const", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
CR39DataFile::trim(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
std::__1::vector<frame*, std::__1::allocator<frame*> >::__append(unsigned long) in CR39DataFile.o
std::__1::vector<std::__1::vector<frame*, std::__1::allocator<frame*> >*, std::__1::allocator<std::__1::vector<frame*, std::__1::allocator<frame*> >*> >::__append(unsigned long) in CR39DataFile.o
"std::__1::__vector_base_common<true>::__throw_out_of_range() const", referenced from:
std::__1::vector<std::__1::vector<frame*, std::__1::allocator<frame*> >*, std::__1::allocator<std::__1::vector<frame*, std::__1::allocator<frame*> >*> >::at(unsigned long) in CR39DataFile.o
std::__1::vector<frame*, std::__1::allocator<frame*> >::at(unsigned long) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::erase(unsigned long, unsigned long)", referenced from:
CR39DataFile::trim(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*)", referenced from:
CR39DataFile::CR39DataFile() in CR39DataFile.o
CR39DataFile::clear() in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::insert(unsigned long, unsigned long, char)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::resize(unsigned long, char)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
DataFile::read(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
DataFile::write(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
std::__1::thread::thread<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void>(bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)&&, DataFile*&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&) in DataFile.o
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
CR39DataFile::write_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
CR39DataFile::write_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, float, float, float, float, float, float, float, float, float) in CR39DataFile.o
CR39DataFile::write_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, float, float, float, float, float) in CR39DataFile.o
...
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, unsigned long, std::__1::allocator<char> const&)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
DataFile::~DataFile() in DataFile.o
DataFile::read(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
DataFile::write(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
std::__1::thread::thread<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void>(bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)&&, DataFile*&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&) in DataFile.o
void* std::__1::__thread_proxy<std::__1::tuple<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(void*) in DataFile.o
std::__1::__tuple_leaf<2ul, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, false>::~__tuple_leaf() in DataFile.o
CR39DataFile::CR39DataFile() in CR39DataFile.o
...
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
CR39DataFile::set_file_path(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
CR39DataFile::set_file_auxpath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::__thread_struct::__thread_struct()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(void*) in DataFile.o
"std::__1::__thread_struct::~__thread_struct()", referenced from:
std::__1::__thread_specific_ptr<std::__1::__thread_struct>::reset(std::__1::__thread_struct*) in DataFile.o
"std::__1::__thread_local_data()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(void*) in DataFile.o
"std::__1::__throw_system_error(int, char const*)", referenced from:
std::__1::thread::thread<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void>(bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)&&, DataFile*&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&) in DataFile.o
"std::__1::thread::~thread()", referenced from:
DataFile::cleanup_file_io() in DataFile.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: *** [Analysis.so] Error 1
I suspect this issue is because of the two C++ runtime libraries available under OS X. Use the following to link the dynamic library:
clang++ -stdlib=libc++ -o Analysis.dylib -shared DataFile.o CR39DataFile.o
(the -stdlib=libc++ being the key difference). I think the default C++ runtime is the GNU implementation which is confusing the linker as you compiled with the libc++ implementation.
As a side note, faced with the same error message, I discovered I needed to use gcc -lstdc++ -lLibraryName ... (the stdc++ part being needed).
See also https://github.com/JonathanSalwan/Triton/issues/243
Compiling this example code for boost::program_options: http://svn.boost.org/svn/boost/trunk/libs/program_options/example/first.cpp
...on MacOS Lion (10.7.2), using boost-1.48.0 installed with MacPorts:
$ clang++ -v
Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.2.0
Thread model: posix
$ clang++ -std=c++0x --stdlib=libc++ -lc++ -I/opt/local/include -L/opt/local/lib -lboost_program_options first.cpp -o first
Undefined symbols for architecture x86_64:
"boost::program_options::options_description::options_description(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, unsigned int)", referenced from:
_main in cc-6QQcwm.o
"boost::program_options::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, boost::program_options::options_description const&)", referenced from:
_main in cc-6QQcwm.o
"boost::program_options::abstract_variables_map::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
boost::program_options::variables_map::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in cc-6QQcwm.o
"boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::__1::pair<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> > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>)", referenced from:
boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::__1::pair<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> > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>) in cc-6QQcwm.o
"boost::program_options::detail::cmdline::cmdline(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&)", referenced from:
boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*) in cc-6QQcwm.o
"boost::program_options::to_internal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > boost::program_options::to_internal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) in cc-6QQcwm.o
"boost::program_options::invalid_option_value::invalid_option_value(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, int*, long) in cc-6QQcwm.o
"boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, 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:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const& boost::program_options::validators::get_single_string<char>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool) in cc-6QQcwm.o
"boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool) const", referenced from:
vtable for boost::program_options::typed_value<int, char> in cc-6QQcwm.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The same code compiled/linked with g++4.7 installed with MacPorts:
$ g++-mp-4.7 -std=c++0x -I/opt/local/include -L/opt/local/lib -lboost_program_options -o first first.cpp
... works fine. As does using clang without libc++:
clang++ -std=c++0x -I/opt/local/include -L/opt/local/lib -lboost_program_options first.cpp -o first
What's wrong? Why does boost::program_options and libc++ not work together?
You need to rebuild boost using clang++ -stdlib=libc++.
libc++ is not binary compatible with gcc's libstdc++ (except for some low level stuff such as operator new). For example the std::string in gcc's libstdc++ is refcounted, whereas in libc++ it uses the "short string optimization". If you were to accidentally mix these two strings in the same program (and mistake them for the same data structure), you would inevitably get a run time crash.
This accident is exactly what has occurred in your case.
In order to turn this run time crash into a link time error, libc++ uses a C++11 language feature called inline namespace to change the ABI of std::string without impacting the API of std::string. That is, to you std::string looks the same. But to the linker, std::string is being mangled as if it is in namespace std::__1. Thus the linker knows that std::basic_string and std::__1::basic_string are two different data structures (the former coming from gcc's libstdc++ and the latter coming from libc++).