Google Filament rendering engine segmentation fault - c++

I am attempting to compile the sample app "Suzanne" from the Filament library, by statically linking to the appropriate libraries. Both the sample app and libraries have been compiled from the latest source code. I am compiling with clang++.
However, when I compile and run the app, I get a segmentation fault. valgrind gives the following output:
==31202== Process terminating with default action of signal 11 (SIGSEGV)
==31202== Access not within mapped region at address 0x8
==31202== at 0x46A485: size (__hash_table:809)
==31202== by 0x46A485: bucket_count (__hash_table:1197)
==31202== by 0x46A485: std::__1::__hash_iterator<std::__1::__hash_node<std::__1::__hash_value_type<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> > >, void*>*> std::__1::__hash_table<std::__1::__hash_value_type<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::__unordered_map_hasher<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<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> > >, true>, std::__1::__unordered_map_equal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<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::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__hash_value_type<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> > > > >::find<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&) (__hash_table:2334)
==31202== by 0x461CA7: find (unordered_map:1205)
==31202== by 0x461CA7: image::KtxBundle::getMetadata(char const*, unsigned long*) const (KtxBundle.cpp:274)
==31202== by 0x463D26: image::KtxBundle::getSphericalHarmonics(filament::math::details::TVec3<float>*) (KtxBundle.cpp:290)
==31202== by 0x420E69: IBL::loadFromKtx(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (in /home/joel/Documents/KiwiTest/filament-suzanne/out/suzanne)
==31202== by 0x42162D: IBL::loadFromDirectory(utils::Path const&) (in /home/joel/Documents/KiwiTest/filament-suzanne/out/suzanne)
==31202== by 0x41A41C: FilamentApp::loadIBL(Config const&) (in /home/joel/Documents/KiwiTest/filament-suzanne/out/suzanne)
==31202== by 0x415D19: FilamentApp::run(Config const&, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*)>, std::__1::function<void (filament::Engine*, filament::View*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*, filament::Renderer*)>, std::__1::function<void (filament::Engine*, filament::View*, filament::Scene*, filament::Renderer*)>, unsigned long, unsigned long) (in /home/joel/Documents/KiwiTest/filament-suzanne/out/suzanne)
==31202== by 0x40A1D4: main (in /home/joel/Documents/KiwiTest/filament-suzanne/out/suzanne)
==31202== If you believe this happened as a result of a stack
==31202== overflow in your program's main thread (unlikely but
==31202== possible), you can try to increase the size of the
==31202== main thread stack using the --main-stacksize= flag.
==31202== The main thread stack size used in this run was 8388608.
Any thoughts on what could be causing this and what I could do to resolve this would be greatly appreciated.

Error resolved (courtesy of TheGoldKnight23): The header files in use were outdated.

Related

Error reading a Trajectory File using Chemfiles library

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)
...

C++: Classic undefined symbols for architecture error

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.

Uninitialised value was created by a heap allocation: Unordered_map

SOLUTION: I can have huge strings, then I have to reserve memory for them. Instead of use string I use char pointer in hash table and therefore I reserve the appropriate memory for my hash table keys.
PROBLEM:
I'm sorry if the question already made, but I could not find any answer that helped me.
I've the following code:
EDIT (the main loop of the problematic function for Valgrind)
i = 0;
wordPos = 0;
for (; it != end; ++it,i++){
// I want to ignore this element on purpose
if (i == 1) continue;
bool isscript;
string tag(it->tagName());
convertToLower(tag);
if (it->isTag()==1){
if (tag=="script") isscript = true;
else isscript = false;
}
if (it->isComment()==0 && it->isTag()==0 && isscript==0){
wordlist.clear();
tokenize(it->text(),wordlist);
int ii = 0;
vector<string>::iterator it_palavras = wordlist.begin();
vector<string>::iterator it_words = wordlist.begin();
int ii = 0;
while(ii<wordlist.size()){
string word(wordlist[ii]);
convertToLower(word);
wordsPos++;
if (voc.find(word) == voc.end()){
voc[word] = countwords;
voc_inv[countwords] = words;
term_pos[countwords] = new vector<int>();
term_pos[countwords]->push_back(wordpos);
countwords++;
}else{
if (term_pos.find(voc[word]) == term_pos.end())
term_pos[voc[word]] = new vector<int>();
term_pos[voc[word]]->push_back(wordpos);
}
ii++;
}
}
The type of voc is unordered_map, but when I run valgrind in my code there is the following message:
EDIT Now I'm pasting the complete error with the flag --track-origins=yes.
EDIT 2 Now I'm pasting the complete error with the flag --—dsymutil=yes.
==21036== Use of uninitialised value of size 8
==21036== at 0x4201FF: _platform_memcmp (in /usr/lib/system/libsystem_platform.dylib)
==21036== by 0x10001F10D: std::__1::__hash_iterator<std::__1::__hash_node<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*> std::__1::__hash_table<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__unordered_map_hasher<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::__unordered_map_equal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int> > >::find<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&) (string:642)
==21036== by 0x10000358F: Colecao::ler_arvore_dom(tree<htmlcxx::HTML::Node, std::__1::allocator<tree_node_<htmlcxx::HTML::Node> > >, int, std::__1::unordered_map<int, std::__1::vector<int, std::__1::allocator<int> >, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<std::__1::pair<int const, std::__1::vector<int, std::__1::allocator<int> > > > >&) (colecao.cpp:135)
==21036== by 0x100002A19: Colecao::ler(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> >) (colecao.cpp:73)
==21036== by 0x100001781: main (index.cpp:47)
==21036== Uninitialised value was created by a heap allocation
==21036== at 0x70AB: malloc (in /usr/local/Cellar/valgrind/HEAD/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==21036== by 0x7528D: operator new(unsigned long) (in /usr/lib/libc++.1.dylib)
==21036== by 0x77E12: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long) (in /usr/lib/libc++.1.dylib)
==21036== by 0x10001A0FF: std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, 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, int> > >::__construct_node(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (memory:1505)
==21036== by 0x10000838D: std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, 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, int> > >::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (unordered_map:1209)
==21036== by 0x100003835: Colecao::ler_arvore_dom(tree<htmlcxx::HTML::Node, std::__1::allocator<tree_node_<htmlcxx::HTML::Node> > >, int, std::__1::unordered_map<int, std::__1::vector<int, std::__1::allocator<int> >, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<std::__1::pair<int const, std::__1::vector<int, std::__1::allocator<int> > > > >&) (colecao.cpp:139)
==21036== by 0x100002A19: Colecao::ler(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> >) (colecao.cpp:73)
==21036== by 0x100001781: main (index.cpp:47)
When I run the code in a huge amount of data I get segmentation fault, and I think it is because of this Valgrind error.
I don't think I need to reserve space for string in unordered_map, then I figured out that is something in word variable constructor. When I initialize word with a static string (for instance, word("test")), Valgrind stops to complain.
I don't know how to fix this string/unordered_map/memory issue.
EDIT: GDB didn't help me. The segmentation fault is only when I use huge amount of data and then huge amount of memory. The only thing GDB give me is Segmentation Fault and memory address nothing more. Valgrind gave me a more complete message.
This might actually be a problem between Valgrind and the memcmp() implementation of your platform (Mac OS X I suppose?).
The uninitialized value in your application supposedly comes from a malloc() call in std::string constructor, the latter of which is unlikely to "create" uninitialized memory on its own. So my guess would be that malloc() allocates a bit more memory than necessary (aligned to 8 bytes maybe), and _platform_memcmp() also takes these bytes into account. System libraries often have highly-optimized implementations of such functions (memcpy, memcmp, strcpy...). As Valgrind often has trouble with these optimizations, it provides own replacement functions (in mc_replace_strmem.c).
Maybe Valgrind lacks these replacements for OS X memcmp(), or your Valgrind version is too old? Also, there might be a setup problem with your system which prevents Valgrind from detecting the memcmp() function at runtime (I'm not familiar with OS X, but maybe you need some kind of debug info for your system libraries).
So, some questions:
are you running the latest Valgrind version? If not, upgrade it.
what OS X version are you using exactly?
does the problem disappear if you disable optimizations when compiling your application?
If this doesn't help, you might want to ask at the Valgrind users mailing list (http://valgrind.org/support/mailing_lists.html) for this specific problem.
Btw. it's pretty difficult to analyze the Valgrind backtraces without any line numbers. See Debugging Symbols Lost When Linking? for a suggestion to get line number info in the backtraces (in short: add "--dsymutil=yes" to Valgrind command line - but check out the notes for this option in http://valgrind.org/docs/manual/manual-core.html#manual-core.erropts first).

linking with clang++ on OS X generates lots of symbol not found errors

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

Why can't clang with libc++ in c++0x mode link this boost::program_options example?

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++).