tknickman
tknickman

Reputation: 4621

Linker error with Boost Threads in C++ in Xcode

I have been trying to get a simple c++ program running that was given to me as an example of multi-thread programming. I know it runs on another machine with boost installed, but I am trying to run it in Xcode, and this is giving me some problems.

First I tried to run it with my existing version of boost. However I was getting many errors and after doing some research, found that I needed to update my boost version from 1.47 to 1.52 to fix a few known threading bugs contained in 1.47.

That fixed many of my errors, but was still throwing a few. SO I found out that I had to patch 1.52 using the patch found here: https://svn.boost.org/trac/boost/attachment/ticket/7671/libcpp_c11_numeric_limits.patch

After all that, I am still getting a linker error saying "Library not found for -lboost_thread"

Right now in Xcode, I have the following project settings: Under search paths, I have the header and library search paths set to "usr/local/include/" - - Under linking I have other linker flags set to "-lboost_thread"

I have both a lboost_thread.a and a lboost_thread.dylib located in usr/local/lib/. How do I make xCode find this, as It seems that should fix my problem.

Also if it helps here is the code I am running:

#include <iostream>
#include <boost/thread.hpp>

using namespace std;

void printNum(char c, int num)
{
    for(int i = 0; i < num; i++)
    {
        cout << c << i << endl;
    }
}

int main()
{
    cout << "Boost threads!" << endl;
    boost::thread t(printNum, 'b', 100);
    printNum('a', 100);
    cout << "Good bye!" << endl;
}

Image of Error: Error

Image showing the file in it's location: libboost_thread.a

Image showing my build settings: xCode build settings

Upvotes: 1

Views: 1726

Answers (2)

Legine
Legine

Reputation: 1

Your screenshot says /usr/local/lib/libboost_thread.a the advice is to use -I/usr/local/lib/libboost_thread.a maybe that is the thing.

Upvotes: 0

JWWalker
JWWalker

Reputation: 22707

I don't know why the linker isn't finding the library, but I can tell you how to circumvent the issue of library search: Add the full path /usr/local/lib/libboost_thread.a to the Other Linker Flags build setting, without -l or -L.

Upvotes: 1

Related Questions