I continue to complain from the g ++ compiler that there are problems in the following code. After a thorough study, I still cannot understand why he cannot find the constructor and destructor of class B from embedMain.cpp.
Can someone give me a little hint?
thanks
// embedMain.cpp
// embed.h
// embed.cpp
~/Documents/C++ $ g++ --version g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 ~/Documents/C++ $ g++ -o embedMain embedMain.cpp /tmp/ccdqT9tn.o: In function `main': embedMain.cpp:(.text+0x42): undefined reference to `B::B(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' embedMain.cpp:(.text+0x6b): undefined reference to `B::~B()' embedMain.cpp:(.text+0x93): undefined reference to `B::~B()' collect2: ld returned 1 exit status
// Updated //
Based on expert comments here, I found the right way to link embedMain.cpp with the built-in library.
Here is the detailed step:
user@ubuntu :~/Documents/C++$ tree . βββ embed.cpp βββ embed.h βββ embedMain.cpp user@ubuntu :~/Documents/C++$ g++ -Wall -c embed.cpp user@ubuntu :~/Documents/C++$ ar -cvq libembed.a embed.o user@ubuntu :~/Documents/C++$ g++ -o embedMain embedMain.cpp -L/home/user/Documents/C++ -lembed user@ubuntu :~/Documents/C++$ tree . βββ embed.cpp βββ embed.h βββ embedMain βββ embedMain.cpp βββ embed.o βββ libembed.a
q0987 source share