Here is another "undefined symbols" problem to add to the plethora of undefined symbols questions on Stack Overflow. Most of my experience is in C, so this is most likely a C++ issue, but it may not be.
I have a header file with the following definitions:
namespace abc {
class Sim {
public:
int mytest();
Regex *RegexComp(std::vector<std::string>, int, int);
}
}
where Regex
is a struct defined elsewhere in the file. I have the implementations in a C file:
Regex *Sim::RegexComp(std::vector<std::string> patterns, int type. int opt) {
// blah blah blah
}
int Sim::mytest() {
cout << "Test\n";
}
I compile this into a shared library (OS X), and if I run nm
on it, it shows that the RegexComp
is being export
shell> nm -g bin/libregex.dylib | c++flit
...
...
0000000000001740 T abc::Sim::RegexComp(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> > > >, int, int)
However, when I attempt to use this library in another file,
mytest()
can be called successfully but RegexComp
results in
Undefined symbols for architecture x86_64:
"udpregex::UdpSim::RegexComp(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, int, int)", referenced from:
_main in ccP5qbaP.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
What is going on here?
Aucun commentaire:
Enregistrer un commentaire