PDA

View Full Version : Boost libraries on OS X




Soulstorm
Mar 23, 2007, 08:48 AM
I thought I should try the boost libraries. So, I downloaded the source but I have a problem understanding what to do.

I have also downloaded Boost.Jam, and installed it. I ran bjam with the current directory set to the directory of the Boost source. I ran it with the command:

bjam "-sTOOLS=gcc" install

But now, where is this supposed to be installed? And how do I use the libraries with XCode?



wittegijt
Mar 23, 2007, 09:51 AM
Boost install in /usr/local by default. Include the necessary headerfiles. Add the library to your project and compile!

Wittegijt.

Soulstorm
Mar 23, 2007, 10:31 AM
Seems you have managed to do it. Can you please tell me how to include the necessary headerfiles to be installed?

Actually, it would be better to briefly tell me how you installed it in the first place. The instructions provided in the boost readme are generic, and I seem to be doing something wrong...

wittegijt
Mar 23, 2007, 12:05 PM
Seems you have managed to do it. Can you please tell me how to include the necessary headerfiles to be installed?

Actually, it would be better to briefly tell me how you installed it in the first place. The instructions provided in the boost readme are generic, and I seem to be doing something wrong...

I've installed Boost some time ago, so I don't remember exactly what I did:)
I just followed the instructions. Do you have the libaries installed?

#include <boost/thread/thread.hpp> (or whatever you want to use)
add /usr/local/include/boost-1_33_1 to your include search path (-I option)
add /usr/local/lib/ to your library rearch path (-L option)

Wittegijt.

wittegijt
Mar 23, 2007, 01:53 PM
Looking at the documentation, I probably would have used:
bjam "-sTOOLS=darwin" install
instead of gcc. Have tried that?

Witegijt.

Soulstorm
Mar 23, 2007, 03:11 PM
Looking at the documentation, I probably would have used:
bjam "-sTOOLS=darwin" install
instead of gcc. Have tried that?

Witegijt.

I have tried that, but I don't think it worked. Where are the files supposed to be?


I only see this in my usr/local/ folder:

http://att.macrumors.com/attachment.php?attachmentid=70769&stc=1&d=1174680589

I am also attaching my terminal output. Something is missing, it seems.

I should note though, that in my boost directory, a folder was created. It's named "bin", and it has inside a folder named "boost". Inside it there are many folders containing many built libraries, dylibs for gcc and darwin. What's this? I have the feeling that everything is compiled but cannot be placed correctly.

Pitfall
Mar 27, 2007, 05:12 AM
Hi,

If you managed to compile the libraries (if I remember correctly they will not be universal by default) you can manually install them. I copied everything in the bin folder to /usr/local/lib. Note that I did NOT copy the directory structure, I only copied the .dilyb and .a files.

As for the headers, there should be a boost directory with headers (.h or .hpp) files, and folders for each boost library. As you can specify where XCode (or, more correctly, gcc) will look for them it is not necessary to "install" them. However I chose to copy them to /usr/local/share/boost_1.33.1.

I hope this helps.

-- EDIT --
Be sure to verify the libraries' install names (otool -L xxx.dylib, the first line is the library install name). This is important because it is the name that the loader (ld) will look for when an executable asks for the library at run time. I chose to strip any path info from the install name (consult the otool man pages) and to add /usr/local/lib to the search path.

I did this a while ago, I hope I'm being clear and that I remember correctly.

Soulstorm
Sep 3, 2008, 03:43 AM
Just a heads up... I finally managed to do this a long time ago. I had written a tutorial on how to do this, here (http://soulstorm-creations.com/PROJECT_SOULSTORM_2_0/index.php?option=com_content&view=article&id=47:xcode-and-boost-liraries-a-setup-tutorial-article&catid=18:programming-articles&Itemid=39). I hope this proves helpful to anyone that has the same problem as me.

Cromulent
Sep 3, 2008, 06:59 AM
Another easier method is to just use Mac Ports :).

Sayer
Sep 3, 2008, 12:44 PM
Another easier method is to frameworktize the resulting dylibs. I got python script from the Adium SVN repository that converts dynamic libs into a framework. I have to build up a convoluted open source UPnP library (using Xcode) into a framework and that script is very handy.

Cromulent
Sep 3, 2008, 12:57 PM
Another easier method is to frameworktize the resulting dylibs. I got python script from the Adium SVN repository that converts dynamic libs into a framework. I have to build up a convoluted open source UPnP library (using Xcode) into a framework and that script is very handy.

I've never attempted that. There are lots of useful libraries out there though that would make fantastic frameworks. May need to look into that.

yeroen
Sep 3, 2008, 10:03 PM
Strange, I don't remember installing boost from source being any more involved than the configure, make, make install sequence.

Soulstorm
Sep 5, 2008, 02:29 PM
Strange, I don't remember installing boost from source being any more involved than the configure, make, make install sequence.

I do, unfortunately. I wrote that guide with a help of a member from another forum, which had the exact same problem.

AlmostThere
Sep 5, 2008, 05:28 PM
I do, unfortunately. I wrote that guide with a help of a member from another forum, which had the exact same problem.

IIRC, most of boost is implemented as header / template files and requires no linking to libraries. It's only those parts that require OS specific implementations that need linking, so you can actually use a large part of it without going through a build / install process.

Soulstorm
Sep 7, 2008, 04:29 AM
IIRC, most of boost is implemented as header / template files and requires no linking to libraries. It's only those parts that require OS specific implementations that need linking, so you can actually use a large part of it without going through a build / install process.

I know. But for example, when I tried using boost::regex, I came into many errors, because boost::regex requires some other files in order to run. Hoever, the includes where in the type #include <something_else.h> and not like #include "something_else.h" as they should be. That caused me many errors. How am I going to get past that?

noogrub
Mar 15, 2009, 12:51 PM
Another easier method is to just use Mac Ports :).

Hi all,
I just completed a Mac Ports install of Boost on my Mac (Leopard).

gcc -v
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5490~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5490)

All I did was:
> sudo port install boost

It seemed successful. Took a long time, maybe 45 mins. But now when I do a simple program (first.cpp):

#include <iostream>
#include<boost/any.hpp>
int main() {
boost::any a(5);
a = 7.67;
std:cout<<boost::any_cast<double>(a)<<std::endl;
}

and then try to compile:
g++ -o first first.cpp

I get this error:
first.cpp:2:24: error: boost/any.hpp: No such file or directory
first.cpp: In function ‘int main()’:
first.cpp:4: error: ‘boost’ has not been declared
first.cpp:4: error: ‘any’ was not declared in this scope
first.cpp:4: error: expected `;' before ‘a’
first.cpp:5: error: ‘a’ was not declared in this scope
first.cpp:6: error: ‘cout’ was not declared in this scope
first.cpp:6: error: ‘boost’ has not been declared
first.cpp:6: error: ‘any_cast’ was not declared in this scope
first.cpp:6: error: expected primary-expression before ‘double’
first.cpp:6: error: expected `;' before ‘double’

Clearly, the compiler does not know where to find the new install of Boost.

I have seen several links with glib comments like "just link to this..." or "include that..", but I would deeply appreciate if someone would show me EXACTLY how that sample program should look in order to get it to properly include boost and compile.

When I do "ports info boost", I get back:
boost @1.37.0 (devel)
Variants: darwin, darwin_9, debug, docs, graphml, icu, openmpi, python24, python25, python26, st

Boost provides free portable peer-reviewed C++ libraries. The emphasis is on portable libraries which work well with the C++
Standard Library.
Homepage: http://www.boost.org

Build Dependencies: boost-jam, gmake
Library Dependencies: zlib, bzip2
Platforms: darwin
Maintainers: sancho*****gmail

I'm convinced that I am simply new and naive and am missing something so simple that an idiot should know it. If someone has successfully installed Boost using Mac Ports, please explain to me precisely why this did not work. I am really stumped. I saw the other "tutorials" but my results do not match.

The most frustrating part is not understanding how to confirm the install, other than to successfully use Boost in a program. Most tutorials say "here's what you SHOULD see" and don't delve into "here's how to figure out what is wrong if you don't".

I esp need to use boost/regex.hpp and can't simply #include<boost/regex.hpp>. It's not that easy!

Best regards, thanks in advance,
John

Cromulent
Mar 15, 2009, 01:12 PM
I'm convinced that I am simply new and naive and am missing something so simple that an idiot should know it. If someone has successfully installed Boost using Mac Ports, please explain to me precisely why this did not work. I am really stumped. I saw the other "tutorials" but my results do not match.

You need to add the header and library search path options in the project settings. Set them to the appropriate folders for the boost library and header files.

noogrub
Mar 15, 2009, 03:40 PM
Thank you for your fast reply. I supposed as much; perhaps there is a g++ config file somewhere? If there is, I don't see it, and I am not finding it by searching the web. I'm sorry to be so terribly dense, but I do not understand what you mean.

I do not have a "project". I am not programming through a GUI of any kind, and so there is no "settings" location(s). I am simply writing that sample first.cpp file in a directory under /Users/username/Documents/C_stuff using a simple text editor.

What I apparently don't know how to do is how to set g++ to know where to find the #include<boost> files. I should add that
g++ -I /path/to/boost -o outfilename file.cpp shows similar errors, but it might be because I don't understand which directory path /path/to/boost is supposed to be.

There's nothing in the world so humbling as programming.

Thanks for your patience and help.
John

noogrub
Mar 16, 2009, 09:00 AM
OK, I figured out how to solve part of my problem.

Using command line g++, there apparently IS no way to set a "path" except to actually explicitly declare it on the command line when compiling, using the "-I" switch.

In my case, I installed Boost using MacPorts, and it ended up in
/opt/local/var/macports/software/boost/1.37.0_0+darwin_9/opt/local/include/boost

However, putting #include<that/entire/11-step/path> into my program did not work, and using
g++ -I that/whole/path/to/boost gave a "File not found" error.

Here's the trick: back up one directory on the -I path statement, like so:
g++ -I /opt/local/var/macports/software/boost/1.37.0_0+darwin_9/opt/local/include/

(note that it looks the same, except I didn't type "boost" on the end)

My first.cpp test file (above) then compiled and ran without complaint. It works to name the directory CONTAINING the boost directory, but not the boost directory itself.

Naming an -I "starting path" for g++ means it will start looking recursively down from that starting path. Since the various boost headers all name their dependencies by saying "boost/whatever", that means if I name "boost" as the starting path, g++ is therefore directed to look in "boost/boost/whatever" and that generates the "File not found" error.

I then did this in my home directory:

ln -s /opt/local/var/macports/software/boost/1.37.0_0+darwin_9/opt/local/include/ boost

This made a symbolic link to that long directory path named simply "boost". That way, I was able to then do this:
g++ -I boost first.cpp -o first
and it compiled just fine. I moved the source file down into a sub-directory, and typed
g++ -I ../boost first.cpp -o first
and that compiled too, because g++ was able to follow the path to the symbolic link, which it could then follow to the actual boost directory.

That must seem like the stupidest most obvious thing in the world to most of you fellows. Hope that helps someone else like me sometime.

Thanks!
John

ragzpad
Jun 20, 2010, 11:36 AM
John !!! Thanks a lot for posting the solution !! It really helped me save a couple of hours !! :)

Detrius
Jun 20, 2010, 02:47 PM
That crazy long MacPorts directory can simply be reduced to "/opt/local/include". You're pointing at the uninstalled copy.



Here's what I do:

Create a folder in your home directory called "Boost." Into that directory, expand the attached zip file. Also, expand your boost tarball. Edit build_boost.sh to make sure that the boost version specified matches the version you want to build.

Run the script. It will build for OS X, iPhone, and iPhone sim. You can enable or disable portions of the script as you please. That is, just comment out the iPhone parts if you don't want to use them. Actually, building for iPhone is very slowly getting better.

Anyway, my favorite part is that when the script is done, it creates a global "BOOST" environment variable that will work in any shell for your user (log out and back in again), and it creates an additional copy that works in Xcode (quit and relaunch). Then, in Xcode, this is what my build settings look like:



OTHER_LDFLAGS = $(BOOST)/lib/libboost_system-xgcc42-mt-$(BOOST_VERSION)-macosx.a
HEADER_SEARCH_PATHS = $(inherited) $(BOOST)/include/boost-$(BOOST_VERSION)/
LIBRARY_SEARCH_PATHS = $(inherited) $(BOOST)/lib
BOOST_VERSION = 1_41



When you build this way (using the user-config.jam files), you have far more control over precisely what gets built and how, including what versions of OS X it will run on. As provided, it should build against the 10.5 SDK but still be able to run on 10.4.

I think.

YMMV.

lloyddean
Jul 18, 2010, 07:27 PM
...

Create a folder in your home directory called "Boost." Into that directory, expand the attached zip file. Also, expand your boost tarball. Edit build_boost.sh to make sure that the boost version specified matches the version you want to build.

Run the script. It will build for OS X, iPhone, and iPhone sim. You can enable or disable portions of the script as you please. That is, just comment out the iPhone parts if you don't want to use them. Actually, building for iPhone is very slowly getting better.

...



I'm not following this.

Lets say I have the following directory structure


MyProject/
`-- ThirdParty/
`-- Boost/
|-- Build_Boost/
| |-- build_boost.sh
| |-- user-config-darwin.jam
| |-- user-config-iphone.jam
| `-- user-config-iphonesim.jam
`-- boost_1_43_0/
`-- ...


How do you suggest I go about executing your 'build_boost.sh' so that it finds everything?

Detrius
Jul 19, 2010, 10:45 PM
The boost source directory should be in the same directory as the script. This creates a few extra directories. One is named "build." This is where the intermediates go (stuff you have no reason to keep). The other is called "installed." The libraries and the include files are all copied here. Assuming everything works, at this point, you no longer need the original boost source directory.

Like so:


MyProject/
`-- ThirdParty/
`-- Boost/
|-- Build_Boost/
| |-- build_boost.sh
| |-- user-config-darwin.jam
| |-- user-config-iphone.jam
| |-- user-config-iphonesim.jam
| |-- boost_1_43_0/
| |-- build/
| |-- installed/
| | |-- include/
| | |-- lib/
`-- ...


Technically, this is independent of your single project and could potentially be used with multiple projects, so it would make more sense outside of the "MyProject" directory, but ultimately, that's just a detail.



What the script does is cd into the boost source code directory. Then it runs bjam with each of the three jam files. Each of these bjam commands culminates in installing the libraries and headers in to the "installed" directory. After all three have finished, user-wide global environment variables are set specifying for you that this is where your Boost installation is located. So far as I'm aware, this is not a Boost standard. It's just what I picked that made sense to me. There are two of these variables. One is visible in any shell. The other is visible to Xcode. Both are named "BOOST" and point to the same place for consistency, but they are technically distinct.

lloyddean
Jul 19, 2010, 11:30 PM
I had all that figured out before the question. The problem is that your directions:


Create a folder in your home directory called "Boost." Into that directory, expand the attached zip file. Also, expand your boost tarball. Edit build_boost.sh to make sure that the boost version specified matches the version you want to build.


result in the directory structure I show above - which of course doesn't work.


Finding accurate instructions for getting boost compiled and functional for iPhone development is hard to come by. Yours is the most direct and useful I've seen but could be even more useful with a slight correction.

Thank you for taking both the time and trouble to post your script and config files.

EDIT: Oh, and the reason for my placement of boost is that it follows the conventions of a former employer whose edutainment product I'm try to update and get working on the iPad. That is any dependent third party libraries must be placed within the working structure of the project for inclusion in the source control system.

Detrius
Jul 21, 2010, 12:50 PM
Does it actually work for iPhone? I've not had a chance to try it myself, but this is as far as I've been able to figure out about building it--with varying results. There are no instructions out there that I've found. I had to read the actual jam files, and they change dramatically between boost releases.

I've also done the same thing for SCM.

About the directions, I reckon I forgot that the zip expands into a directory. Oops.

lloyddean
Jul 21, 2010, 09:07 PM
Well, I had to modify it for the version of Xcode (xcode_3.2.3_and_ios_sdk_4.0.1.dmg) I've got installed, after which only the Simulator build completed correctly.

I was able to compile and link against the build of simulator static libraries; the test program compiled, linked and ran.

I've since deleted and reinstalled the latest Xcode release just in case something was left behind from one of the many preview versions that had been previously installed.

It looks like I won't get any further than that today. But I'll let you know what I come up with in the next couple of days.

fafonso
Aug 27, 2010, 01:14 PM
Hi I'm new here and I've a problem slightly different with boost. I've installed it by macports, but I'm using Eclipse. I already had the include and lib folders to the include files and lib paths of Eclipse, however I can not compile the program

I hope someone can help me.

Thanks
Fábio

lloyddean
Aug 27, 2010, 02:37 PM
What do you mean by "... I can not compile the program"?
What program?
What error messages if any?
What computer language are you compiling for?
What do you plan to do with this program once it's completed?
Do you intend to distribute to others?

I have more questions if you have answers.

fafonso
Aug 28, 2010, 06:08 PM
I'm a master degree student and I'm building a prototype to efficiently compute similarity searches over trajectories.

The program is only an example of the use of boost to make directories independently from the OS:

#include <iostream>
#include <string>
#include <cstdlib>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>

using namespace std;
using namespace boost::filesystem;

int main(int argc, char** argv) {

// Parameter checking...

try {
path p = complete(path(argv[1], native));
create_directory(p);
}
catch (exception& e) {
cerr << e.what( ) << endl;
}

return(EXIT_SUCCESS);
}

When I compile this the following errors occurs:

Building target: lixo
Invoking: MacOS X C++ Linker
g++ -L/opt/local/lib -o "lixo" ./src/lixo.o
Undefined symbols:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in lixo.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in lixo.o
__static_initialization_and_destruction_0(int, int)in lixo.o
"boost::filesystem2::detail::create_directory_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
boost::enable_if<boost::filesystem2::is_basic_path<boost::filesystem2::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem2::path_traits> >, bool>::type boost::filesystem2::create_directory<boost::filesystem2::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem2::path_traits> >(boost::filesystem2::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem2::path_traits> const&)in lixo.o
"boost::filesystem2::detail::get_current_path_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)", referenced from:
boost::filesystem2::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem2::path_traits> boost::filesystem2::current_path<boost::filesystem2::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem2::path_traits> >()in lixo.o
"boost::filesystem2::native(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
_main in lixo.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [lixo] Error 1


The language is C++

Hope to have answered all your questions ;)

lloyddean
Aug 28, 2010, 06:56 PM
I had removed my MacPorts build of boost and am in the process of reinstalling it so can't give you a proper answer but it looks like you haven't specified what boost library to link against. It should be something along the lines of:

-lboost_filesystem -llboost_system

added to your invocation of gcc.

lloyddean
Aug 29, 2010, 01:52 PM
gcc lixo.mm -I/opt/local/include -L/opt/local/lib -lboost_filesystem -lboost_system -o "lixo"

fafonso
Aug 30, 2010, 08:42 AM
Thank you a lot, it is now working :)

lloyddean
Aug 30, 2010, 02:29 PM
Congratulations!

Please be aware, thus some of the (unanswered) questions above, that the Mac linker will always prefer shared dynamic libraries, when they exist, over static libraries.

What this means is even though you may explicitly specify a static library to link against if a shared library exists it will be used instead. This has implications in that if you plan to distribute your application to systems which don't have Mac Ports and Boost installed the application will fail to find, load and link to the shard dynamic library that doesn't exist.

fafonso
Aug 31, 2010, 03:49 PM
thanks a lot for the warning, I will be carful with that :)

aaptuster
Nov 5, 2010, 11:41 AM
Hi,

I am new to Mac :) So, I need the help of Mac Pros over here.

I am using Xcode (3.1), and I am trying to add boost library to it. I have completed the steps of building the library using bjam tool and I find that the right path is being pointed to during build, however, compilation of code goes fine and linking fails.

Details:

I am using boost threads in my minor example code.

Error thrown and command:

Ld build/Debug/trial normal x86_64
cd /Users/siddharthshankaran/Documents/trial
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/siddharthshankaran/Documents/trial/build/Debug -L/Users/siddharthshankaran/Library/boost_1_43_0/stage/lib -F/Users/siddharthshankaran/Documents/trial/build/Debug -filelist /Users/siddharthshankaran/Documents/trial/build/trial.build/Debug/trial.build/Objects-normal/x86_64/trial.LinkFileList -mmacosx-version-min=10.6 -o /Users/siddharthshankaran/Documents/trial/build/Debug/trial




Undefined symbols:
"typeinfo for boost::detail::thread_data_base", referenced from:
typeinfo for boost::detail::thread_data<void (*)()>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
"boost::detail::thread_data_base::~thread_data_base()", referenced from:
boost::detail::thread_data<void (*)()>::~thread_data()in main.o
boost::detail::thread_data<void (*)()>::~thread_data()in main.o
"vtable for boost::detail::thread_data_base", referenced from:
boost::detail::thread_data_base::thread_data_base()in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status



structure of my boost library:

bash-3.2$ ls *thread*
libboost_thread-xgcc42-mt-1_43.a libboost_thread-xgcc42-mt-s.a
libboost_thread-xgcc42-mt-1_43.dylib libboost_thread-xgcc42-mt-sd-1_43.a
libboost_thread-xgcc42-mt-d-1_43.a libboost_thread-xgcc42-mt-sd.a
libboost_thread-xgcc42-mt-d-1_43.dylib libboost_thread-xgcc42-mt.a
libboost_thread-xgcc42-mt-d.a libboost_thread-xgcc42-mt.dylib
libboost_thread-xgcc42-mt-d.dylib libboost_thread.a
libboost_thread-xgcc42-mt-s-1_43.a libboost_thread.dylib
bash-3.2$ pwd
/Users/siddharthshankaran/Library/boost_1_43_0/stage/lib


What possibly could be wrong now? Compilation succeed and its only the linking part that's failing. Please help in this.

Or else, suggest me some way to redo it form scratch in a way that it would work! Thanks in advance!! :apple:

Golker
Sep 2, 2011, 05:40 PM
OK, I figured out how to solve part of my problem.

Using command line g++, there apparently IS no way to set a "path" except to actually explicitly declare it on the command line when compiling, using the "-I" switch.

In my case, I installed Boost using MacPorts, and it ended up in
/opt/local/var/macports/software/boost/1.37.0_0+darwin_9/opt/local/include/boost

However, putting #include<that/entire/11-step/path> into my program did not work, and using
g++ -I that/whole/path/to/boost gave a "File not found" error.

Here's the trick: back up one directory on the -I path statement, like so:
g++ -I /opt/local/var/macports/software/boost/1.37.0_0+darwin_9/opt/local/include/

(note that it looks the same, except I didn't type "boost" on the end)

My first.cpp test file (above) then compiled and ran without complaint. It works to name the directory CONTAINING the boost directory, but not the boost directory itself.

Naming an -I "starting path" for g++ means it will start looking recursively down from that starting path. Since the various boost headers all name their dependencies by saying "boost/whatever", that means if I name "boost" as the starting path, g++ is therefore directed to look in "boost/boost/whatever" and that generates the "File not found" error.

I then did this in my home directory:

ln -s /opt/local/var/macports/software/boost/1.37.0_0+darwin_9/opt/local/include/ boost

This made a symbolic link to that long directory path named simply "boost". That way, I was able to then do this:
g++ -I boost first.cpp -o first
and it compiled just fine. I moved the source file down into a sub-directory, and typed
g++ -I ../boost first.cpp -o first
and that compiled too, because g++ was able to follow the path to the symbolic link, which it could then follow to the actual boost directory.

That must seem like the stupidest most obvious thing in the world to most of you fellows. Hope that helps someone else like me sometime.

Thanks!
John

I know this is a stupidly old topic, but I just wanted to thank you for this answer :)
It really helped me. I also miss the option of not having to put "boost" in the g++ command line, but, at least it's working. Just dont get why people from Boost.org dont make a keener installer for Mac OS X. Linux's installer works like a charm, and havent tried Windows', but I assume it's just as easy, so why not Mac too? :)

Anyway, thanks again!

mghiggins
Sep 13, 2011, 11:58 AM
I installed boost 1.47 using MacPort and want to use it from XCode 4.

I'm running into problems though and don't understand what the error messages imply; maybe someone here can help...

I did the usual boost install using MacPort, which installed headers in /opt/local/include and libraries in /opt/local/lib.

I added /opt/local/include/** (ie recursive) into my Header Search Path for the project. If I then try to build *any* code - even code that does not #include any boost libraries - it fails to build in the standard c++locale.h file. ie not a link error (and added /opt/local/lib/** into the library search path doesn't affect things). The error message is:

No member named 'vsnprintf' in namespace 'std'

The same build error appears 15 times in that same file. No other build errors.

I haven't seen any other examples of this error associated with boost when I google around, so I'm a bit lost! Any help appreciated.

mghiggins
Sep 13, 2011, 01:34 PM
I installed boost 1.47 using MacPort and want to use it from XCode 4.

I'm running into problems though and don't understand what the error messages imply; maybe someone here can help...

I did the usual boost install using MacPort, which installed headers in /opt/local/include and libraries in /opt/local/lib.

I added /opt/local/include/** (ie recursive) into my Header Search Path for the project. If I then try to build *any* code - even code that does not #include any boost libraries - it fails to build in the standard c++locale.h file. ie not a link error (and added /opt/local/lib/** into the library search path doesn't affect things). The error message is:

No member named 'vsnprintf' in namespace 'std'

The same build error appears 15 times in that same file. No other build errors.

I haven't seen any other examples of this error associated with boost when I google around, so I'm a bit lost! Any help appreciated.

Sorted it out - in the header search path I just need to click *off* Recursive. Then it all works. Surprising though since I don't see how, if I include /opt/local/include, it can see the headers in the boost directory that's inside include... anyways, that's the fix.