can't get first example in boost tutorial to work
I'm trying to install boost on mac osx 10.4.7. I followed
the tutorial "Getting Started on Unix Variants" found here:
http://www.boost.org/doc/libs/1_35_0/
more/getting_started/unix-variants.html
Following the instructions in the tutorial, I installed
boost in /usr/local as instructed, so my directory
structure is:
/usr/local/boost_1_34_1/boost
But when I run the first example in the tutorial:
#include
On Sun, Apr 20, 2008 at 03:35:27AM +0000, 7stud wrote:
Following the instructions in the tutorial, I installed boost in /usr/local as instructed, so my directory structure is:
/usr/local/boost_1_34_1/boost
I also tried to execute the program from the command line with the original include path:
#include
but I get the same error:
~/2testing/dir1$ g++ prog1.cpp prog1.cpp:1:35: error: boost/lambda/lambda.hpp:
You need of course to specify /usr/local/boost_1_34_1 as include path via -isystem /usr/local/boost_1_34_1 or -I /usr/local/boost_1_34_1 so that the compiler knows where to find boost header files. Jens
Jens Seidel
On Sun, Apr 20, 2008 at 03:35:27AM +0000, 7stud wrote:
Following the instructions in the tutorial, I installed boost in /usr/local as instructed, so my directory structure is:
/usr/local/boost_1_34_1/boost
I also tried to execute the program from the command line with the original include path:
#include
but I get the same error:
~/2testing/dir1$ g++ prog1.cpp prog1.cpp:1:35: error: boost/lambda/lambda.hpp:
You need of course to specify /usr/local/boost_1_34_1 as include path via -isystem /usr/local/boost_1_34_1 or -I /usr/local/boost_1_34_1 so that the compiler knows where to find boost header files.
Jens
Here is the tutorial example:
#include
On Sun, Apr 20, 2008 at 07:36:58PM +0000, 7stud wrote:
Here is the tutorial example:
#include
#include <iostream> #include <iterator> #include <algorithm> int main() { using namespace boost::lambda; typedef std::istream_iterator<int> in;
std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " " ); return 0; }
And this is what happens:
gcc -I /usr/local/boost_1_34_1 prog1.cpp
Please use the C++ compiler "g++" instead of the C compiler "gcc".
/usr/bin/ld: Undefined symbols:
Ah, OK, now the compiler error vanished as the compiler is able to find the header files of boost. [The following can probably be ignored as I missed at the beginning the you used the C compiler. Nevertheless you may find the next usful in you later steps:] Now the linker complains about symbols (such as functions) defined in a Boost library which you have to link against. You need for linking the additional options -L /usr/local/boost_1_34_1/lib/ (to specify the library search path) -l boost??? (to specify the library) Sorry, I do not remember the library name which contains lambda. Just look into your /usr/local/boost_1_34_1/ for available dynamic lib/libboost*.so or lib/libboost*.a static libraries and choose the right one (without lib prefix or .so or a suffix). Please note that this kind of question indicate that you are not very familiar with a C++ compiler. That's not a problem but please try to find such answers yourself by following more basic C++/g++ tutorials. Starting with a simple "Hello world" program is typically the first step. Jens
Jens Seidel
Please use the C++ compiler "g++" instead of the C compiler "gcc".
Whoops. Somewhere between my first post and my second post I began using the gcc command instead of the g++ command. The program compiles fine when I use the command: g++-I /usr/local/boost_1_34_1 prog1.cpp
/usr/bin/ld: Undefined symbols:
Ah, OK, now the compiler error vanished as the compiler is able to find the header files of boost.
[The following can probably be ignored as I missed at the beginning the you used the C compiler. Nevertheless you may find the next usful in you later steps:]
Now the linker complains about symbols (such as functions) defined in a Boost library which you have to link against.
You need for linking the additional options -L /usr/local/boost_1_34_1/lib/ (to specify the library search path) -l boost??? (to specify the library)
Sorry, I do not remember the library name which contains lambda. Just look into your /usr/local/boost_1_34_1/ for available dynamic lib/libboost*.so or lib/libboost*.a static libraries and choose the right one (without lib prefix or .so or a suffix).
Please note that this kind of question indicate that you are not very familiar with a C++ compiler.
You are right. I am not familiar with the gcc compilers. I've used MS VC++6 for about 10 years to write and compile C++ programs, but I recently switched from windows to a mac. Mac's have an IDE called Xcode for writing and compiling C++ programs, and that's what I've been using recently.
That's not a problem but please try to find such answers yourself by following more basic C++/g++ tutorials.
Starting with a simple "Hello world" program is typically the first step.
I can compile a 'hello' world problem using the command line, but that's about it.
Jens Seidel
On Sun, Apr 20, 2008 at 03:35:27AM +0000, 7stud wrote:
Following the instructions in the tutorial, I installed boost in /usr/local as instructed, so my directory structure is:
/usr/local/boost_1_34_1/boost
I also tried to execute the program from the command line with the original include path:
#include
but I get the same error:
~/2testing/dir1$ g++ prog1.cpp prog1.cpp:1:35: error: boost/lambda/lambda.hpp:
You need of course to specify /usr/local/boost_1_34_1 as include path via -isystem /usr/local/boost_1_34_1 or -I /usr/local/boost_1_34_1 so that the compiler knows where to find boost header files.
Jens
And when I try running the program in the Xcode 2.4 IDE, I get different errors. I added the directory /usr/local/boost_1_34_1 to the Project Settings under: Project>Edit Project Settings Collection: Search Paths Header Search Paths /usr/local/boost_1_34_1/** And when I run the program, I get an error for the line: typedef std::istream_iterator<int> in; which says: error: expected initializer before token '<' token And I get an error for the line: std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " " ); which says: error: for_each is not a member of 'std' (plus 170 other errors)
On Sun, Apr 20, 2008 at 07:49:28PM +0000, 7stud wrote:
And when I try running the program in the Xcode 2.4 IDE, I get different errors. I added the directory /usr/local/boost_1_34_1 to the Project Settings under:
Project>Edit Project Settings Collection: Search Paths Header Search Paths /usr/local/boost_1_34_1/**
And when I run the program, I get an error for the line:
typedef std::istream_iterator<int> in;
which says:
error: expected initializer before token '<' token
It works for me. Please check that you use indeed a C++ compiler not a C one. Maybe adding (after all other #include-statements in the example) #include <iterator> helps to make this error go away?
And I get an error for the line:
std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " " );
which says:
error: for_each is not a member of 'std'
for_each is defined in algorithm which is included ... Try: #include <iostream> int main() { std::cout << "Hello World. This is my first C++ program\n"; return 0; } Jens
Jens Seidel
It works for me. Please check that you use indeed a C++ compiler not a C one.
Are you using Xcode? I can't find a setting in Xcode for the compiler. When I create a new project, I choose Command Line Utility>C++ Tool. Then Xcode creates the project for me. I don't know what I should do to run the boost program in Xcode.
On Mon, Apr 21, 2008 at 01:36:41AM +0000, 7stud wrote:
Jens Seidel
writes: It works for me. Please check that you use indeed a C++ compiler not a C one.
Are you using Xcode?
Of course not! Please always restrict to free tools every person has access to. Xcode is probably not free otherwise I would find it in my Linux distribution. That's also the reason why you should always, again, always, start from the command line to understand the basic problems. Any kind of GUI (graphical environment) is an additional layer which requires that you have knowledge of the previous ones. Calling a compiler from the command line is the most basic stuff every coder has to know. Really.
I can't find a setting in Xcode for the compiler.
This doesn't matter. Any GUI related question should not be asked on this list. Can you again post your code together with the first (let's say 30) error lines? If it doesn't work it is maybe because the C++ compiler isn't properly installed? Please try also other examples of using boost. Sometimes a specific example of the Boost library is just faulty, yep, this happens. (In this case you shouldreport it, so that it can be fixed.) Jens
Jens Seidel
On Mon, Apr 21, 2008 at 01:36:41AM +0000, 7stud wrote:
Jens Seidel
writes: It works for me. Please check that you use indeed a C++ compiler not a C one.
Are you using Xcode?
Of course not! Please always restrict to free tools every person has access to. Xcode is probably not free otherwise I would find it in my Linux distribution.
Then don't respond to a post asking about Xcode by saying, "It works for me" !
This doesn't matter. Any GUI related question should not be asked on this list.
This is a general boost users list, therefore I think it's appropriate to ask how boost interacts with IDE's.
On Mon, Apr 21, 2008 at 09:09:06AM +0000, 7stud wrote:
Jens Seidel
writes: On Mon, Apr 21, 2008 at 01:36:41AM +0000, 7stud wrote:
Jens Seidel
writes: It works for me. Please check that you use indeed a C++ compiler not a C one.
Are you using Xcode?
Of course not! Please always restrict to free tools every person has access to. Xcode is probably not free otherwise I would find it in my Linux distribution.
Then don't respond to a post asking about Xcode by saying, "It works for me" !
The code works indeed for me and compiles cleanly (at least with g++ 4.1.2).
This doesn't matter. Any GUI related question should not be asked on this list.
This is a general boost users list, therefore I think it's appropriate to ask how boost interacts with IDE's.
No, as Boost is completely independent of any GUI. If you're not able to use a GUI don't use it! Jens
7stud wrote:
This doesn't matter. Any GUI related question should not be asked on this list.
This is a general boost users list, therefore I think it's appropriate to ask how boost interacts with IDE's.
Maybe :-) The thing is we know this works just fine with current g++ releases, so... * What version of gcc are you using? * What is the actual command line issued by the IDE when building? Sorry, but since most of us aren't XCode users, we're not familiar with that IDE or what the potential traps might be. John.
On 4/21/08 12:59 AM, "Jens Seidel"
Please always restrict to free tools every person has access to.
<snip>
Any GUI related question should not be asked on this list.
Discussion of tools related the use of Boost Libraries is appropriate for this list without regard to the nature of those tools. If you have questions or concerns about content of Boost-User postings, please address them to boost-users-owner@lists.boost.org, not to this list. Thanks to all for your understanding. And to all of you that, like Jens, help others by answering the questions posted here, a big on-going thank you. -- Jon Kalb Jon@KalbWeb.com Boost-Users moderator
On 21/04/2008, 7stud
Are you using Xcode? I can't find a setting in Xcode for the compiler. When I create a new project, I choose Command Line Utility>C++ Tool. Then Xcode creates the project for me. I don't know what I should do to run the boost program in Xcode.
I don't normally use Xcode, but I had a quick look. If you start a C++ project, choose 'edit project settings' from the project menu then select the 'build' tab there are options for 'Header Search Paths' which is probably what you need to set. I expect you need to add '/usr/local/boost_1_34_1' to 'Header Search Paths'. You might have better luck asking on an Xcode mailing list. I found a thread starting at: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00270.html If you look through the replies there's some useful information. Daniel
Daniel James
On 21/04/2008, 7stud
wrote: Are you using Xcode? I can't find a setting in Xcode for the compiler. When I create a new project, I choose Command Line Utility>C++ Tool. Then Xcode creates the project for me. I don't know what I should do to run the boost program in Xcode.
I don't normally use Xcode, but I had a quick look. If you start a C++ project, choose 'edit project settings' from the project menu then select the 'build' tab there are options for 'Header Search Paths' which is probably what you need to set. I expect you need to add '/usr/local/boost_1_34_1' to 'Header Search Paths'.
From one of my earlier posts:
---- And when I try running the program in the Xcode 2.4 IDE, I get different errors. I added the directory /usr/local/boost_1_34_1 to the Project Settings under: Project>Edit Project Settings Collection: Search Paths Header Search Paths /usr/local/boost_1_34_1/** And when I run the program, I get an error for the line: typedef std::istream_iterator<int> in; which says: error: expected initializer before token '<' token And I get an error for the line: std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " " ); which says: error: for_each is not a member of 'std' ----------
2008/4/23 7stud
From one of my earlier posts:
Sorry, I missed that one.
Header Search Paths /usr/local/boost_1_34_1/**
If you really have two asterisks at the end of that setting you should remove them, although from the errors it looks like you don't so I assume that was a copy and paste quirk.
error: expected initializer before token '<' token error: for_each is not a member of 'std'
These errors suggest that the headers <iterator> and <algorithm> are not included. Check that you haven't changed the include lines for those headers. If they're still there, then you might have accidentally changed the system include path when trying to set up the include path for the boost headers - so creating a project from scratch might work.
Discovery Options] I accepted the configuration (Debug [Active]) and selected the tool (GCC C++ Compiler). Down near the bottom of the pane is a field titled "Compiler invocation arguments". To the text that was already
I had the same problem with the same error messages when trying to compile the first sample program from the Boost getting-started tutorial in Eclipse using the MinGW GNU g++ compiler in Microsoft Windows. I finally found an explanation of what's going on at the MinGW website posting "HOWTO Specify the Header File Include Path for use with MinGW Compilers" at http://www.mingw.org/wiki/IncludePathHOWTO . It turns out that MinGW doesn't read the Windows "Include" environment variable. You have to specify the boost home directory using one of the ways described in the section "Including Headers from Directories which are Not Searched by Default" which is about two-thirds of the way down the page. In my case, I opened up the Properties window for my project, then went to [C/C++ General > Paths and Symbols], where I found a tab labeled [Includes]. I clicked on the language I'm using (GNU C++), then the [Add..] on the right side of the pane. There, I entered the directory name (on my system, it is C:\Programm Files\Boost_1_53_0 ). After I did that, things went more smoothly, but I still got one more error message. A compilation message popped up (generated by the source code, not the compiler itself) explaining that the Boost library required another setting on the command line (either " -std=c++11" or " -std=gnu++11"). Back in the Properties window, this time under [C/C++ Build there I appended " -std=gnu++11" (or maybe it was " -std=c++11" ? They're both there now.) I hope this helps! Richard Daehler-Wilking -- View this message in context: http://boost.2283326.n4.nabble.com/can-t-get-first-example-in-boost-tutorial... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (6)
-
7stud
-
daehlerr
-
Daniel James
-
Jens Seidel
-
John Maddock
-
Jon Kalb