Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

andys0723

macrumors newbie
Original poster
Feb 28, 2012
2
0
Hi

I am noob to XCODE C++. I am trying to use Boost library. The boost library was installed by MACPort. Once loading is done, I create a c++ project from Xcode. The is some code below:
#include <iostream>
#include <boost/thread.hpp>

void task1() {
// do stuff}

void task2() {
// do stuff}

int main (int argc, const char * argv[])
{

using namespace boost;
thread thread_1 = thread(task1);
thread thread_2 = thread(task2);

// do other stuff
thread_2.join();
thread_1.join();
return 0;
}

since boost library is stored in /opt/local/include/boost, "Header Search Path" is set to "/opt/local/include" and "Library Search Paths" was set to"/opt/local/bin." But When the main is built, I got some error and couldn't figure out. The error was shown below.
ld: warning: directory not found for option '-L/opt/ocal/bin'
Undefined symbols for architecture x86_64:
"boost::thread::~thread()", referenced from:
_main in main.o
"boost::thread::join()", referenced from:
_main in main.o
"boost::thread::start_thread()", referenced from:
boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type) in main.o
"vtable for boost::detail::thread_data_base", referenced from:
boost::detail::thread_data_base::thread_data_base() in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"boost::detail::thread_data_base::~thread_data_base()", referenced from:
boost::detail::thread_data<void (*)()>::~thread_data() in main.o
"typeinfo for boost::detail::thread_data_base", referenced from:
typeinfo for boost::detail::thread_data<void (*)()> 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

Can any one suggest how to fix?
And please suggest how to set external library?

Thanks
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
...and "Library Search Paths" was set to"/opt/local/bin."

No, it wasn't.

Read the first linker warning carefully.

Bonus points to you for including the relevant information in the post. Many posters don't do that, leading to a wild goose chase.
 

andys0723

macrumors newbie
Original poster
Feb 28, 2012
2
0
Please explain clearly

I still couldn't get the point.

So if I set "Header Search Path"->/opt/local/include/
->/opt/local/include/boost
And "Library Search Paths" -> /opt/local/bin
And "other Linker Flags" ->-libboost_thread-mt.a

The error came out below
Ld /Users/andys0723/Library/Developer/Xcode/DerivedData/parserc++-cfwhbmlhhzlmvngjnwzkujhqsxda/Build/Products/Debug/parserc++ normal x86_64
cd "/Users/andys0723/Documents/Mobile Class/parserc++"
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang++ -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/andys0723/Library/Developer/Xcode/DerivedData/parserc++-cfwhbmlhhzlmvngjnwzkujhqsxda/Build/Products/Debug -L/opt/local/bin -F/Users/andys0723/Library/Developer/Xcode/DerivedData/parserc++-cfwhbmlhhzlmvngjnwzkujhqsxda/Build/Products/Debug -filelist /Users/andys0723/Library/Developer/Xcode/DerivedData/parserc++-cfwhbmlhhzlmvngjnwzkujhqsxda/Build/Intermediates/parserc++.build/Debug/parserc++.build/Objects-normal/x86_64/parserc++.LinkFileList -mmacosx-version-min=10.7 -libboost_thread-mt.a -o /Users/andys0723/Library/Developer/Xcode/DerivedData/parserc++-cfwhbmlhhzlmvngjnwzkujhqsxda/Build/Products/Debug/parserc++

ld: library not found for -libboost_thread-mt.a
Command /Developer/usr/bin/clang++ failed with exit code 1

Library not found for -libboost_thread-mt.a




I am confused with finding lib. And what exactly the other link flag is supposed to be put??

Please advise how to add Library.:confused:
I got project due on this week.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
I still couldn't get the point.
I got project due on this week.

Well, you fixed one problem, right? If you had read the warning, you could have fixed it yourself.

So you get another error. It seems you added this "linker flag" later, and it seems to cause a problem. It looks like you are using the name of an assembler file as a linker flag which doesn't make sense. I'd check what happens without the linker flag.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.