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 !
Learning C++ lately, and I'm having trouble to compile my classes. I am currently getting the following obscure template error:
Undefined symbols for architecture x86_64:
"SmallWorld::AJV::validate(nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>*, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>*)", referenced from:
SmallWorld::Map::(anonymous namespace)::readMap(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 map.test.cpp.o
"std::__1::function<unsigned long (SmallWorld::Map::Graph<SmallWorld::Region>)> SmallWorld::Map::algorithm::dfs<SmallWorld::Region>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<bool (std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<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> > > >&, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 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::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, 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> > > > > > const&)> const&)", referenced from:
creates_a_connected_graph_small_world_map_Test::TestBody() in map.test.cpp.o
"SmallWorld::Region::Region(nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>)", referenced from:
std::__1::shared_ptr<SmallWorld::Region> std::__1::shared_ptr<SmallWorld::Region>::make_shared<nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer> const&>(nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer> const&&&) in map.test.cpp.o
ld: symbol(s) not found for architecture x86_64
which can be simplified to:
Undefined symbols for architecture x86_64:
"SmallWorld::AJV::validate(nlohmann::json*, nlohmann::json*)", referenced from:
SmallWorld::Map::(anonymous namespace)::readMap(string const&, string const&) in map.test.cpp.o
"std::function<size_t(Graph<Region>)> SmallWorld::Map::algorithm::dfs<SmallWorld::Region>(string const&, std::function<bool (string const&, std::set<string> const&, std::unordered_map<string, string> const&)", referenced from:
creates_a_connected_graph_small_world_map_Test::TestBody() in map.test.cpp.o
"SmallWorld::Region::Region(nlohmann::json)", referenced from:
std::shared_ptr<SmallWorld::Region> std::shared_ptr<SmallWorld::Region>::make_shared<nlohmann::json const&&&) in map.test.cpp.o
ld: symbol(s) not found for architecture x86_64
Which to me seems like it is saying that the method bool AJV::validate(json* schema, json* data) does not exist on type AJV. However I have verified the common mistakes (different implementation from header declaration, different invocation from implementation), to no avail.
Here is the definition and implementation of the AJV class:
// AJV.h
#ifndef SMALLWORLD_AJV_H
#define SMALLWORLD_AJV_H
#include <nlohmann/json.hpp>
using nlohmann::json;
namespace SmallWorld {
class AJV {
public:
std::function<bool(json*)> compile(json* schema);
bool validate(json* schema, json* data);
json errors;
private:
json m_schema;
std::function<bool(json*)> m_validator;
};
};
#endif // SMALLWORLD_AJV_H
// AJV.cpp
#include <nlohmann/json.hpp>
#include "AJV.h"
using nlohmann::json;
namespace SmallWorld {
std::function<bool(json*)> AJV::compile(json* schema) {
return [](json* data){ return true; };
};
bool AJV::validate(json* schema, json* data){ return true; };
};
And here is the invocation:
//loader.cpp
json* readMap(const string& map_path, const string& schema_path) {
AJV ajv;
json* schema = readJSONFile(schema_path);
json* jmap = readJSONFile(map_path);
if(ajv.validate(schema, jmap)){
delete schema;
return jmap;
}else{
delete schema;
throw ajv.errors;
}
};
Setup:
OS: MacOS 10.13.3
C++ Version: 14
Compiler: g++ => Apple LLVM version 9.0.0 (clang-900.0.39.2)
Build manager: CMake 3.5.1
IDE: Atom IDE w/ linter-clang for linting (not really an IDE XD)
Additional Details
Compilation is done via command line: mkdirp build && cd build && cmake .. && make
File AJV.h is within source tree at the specified include path.
How can I solve this problem?
Cheers ☀️
When you register a project in CMake, you list both headers and source files. It will then deal with these as best it can for the respective IDE / build system that you tell it to use.
If you always have one header and one cpp file (there's no requirement to; you may find some objects are complex/large enough that you want to split it into multiple cpp files for your sanity) then you could list all your file names with no extension in the cmake and have it append the .cxx and .h to the end for you. This will leave you with just half the typing.
As an alternative there is a non-recommended route which is to to use the file command to scan the directory for files - but this is done only when cmake is run; and as such will not auto-update; leaving it possible to have a source tree that's building fine on one system; while not on another.
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++).