Hey guys not sure if the Lounge is the appropriate category to ask this question under but I'm having trouble installing the Boost libraries to my IDE/compiler. I'm using Code::Blocks and have been following instructions posted in their Wiki (located: http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef ).
I currently have all the Boost stuff on my desktop and am trying to install it to the root program files directory inside CodeBlocks.
I was wondering if someone can help me. I know this is vague but I'm not sure if posting all the CMD errors/statements would help. I've tried it twice now and the second time I uninstalled and then re-installed Code::Blocks.
I'm thinking it might have to do something with the fact that the IDE came with Mingw and so that's where the problem might lie.
Anyways any assistance in this matter is appreciated. Thanks.
I'm not sure. Code::Blocks simply says that no such file or directory found.
This is the code i'm trying to run. I believe I found this in the documentation for Boost.Regex.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <boost/regex.hpp> // This is where the error occurs.
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
I installed Boost to here ( C:\Program Files\CodeBlocks\MinGW ) I believe. But even still, I don't see a directory where all the files have been copied to and maybe a directory labeled Boost or something.
I think I'm maybe screwing up with the install process.
By copying the files manually to the respective directories, it is able to find the libraries but doesn't execute because of some sort of error with classes i'm thinking. The errors can be found in the link below.
Do you guys think that I should reinstall CodeBlocks and Boost? Maybe the compiler has some sort of internal problem recognizing the library...?
I appreciate the help so far. Its vital for me to install Boost for a project i'm working on. Actually I only need Boost.Regex but I'm not sure if you can install the Boost libraries individually. Plus I need a library that is based on PERL syntax and therefore Boost.Regex seemed like the appropriate one.
Anyways apologies because I know I can/am vague at times but I have no idea on how to execute a simple task as installation. Thanks! :)
You cannot copy the files out of the archive and expect them to work. Specifically, the few libraries that require compilation (Boost.Regex is one of them) will not work (you'll get undefined reference errors).
Now, once boost is installed properly, you're not done just yet. You'll still have to tell the compiler where to find the headers and libraries. If it does not find the libraries, you'll also get undefined reference errors.
I think maybe you guys can give me some guidance on building a program that formats code. The way I was planning it that I would run some sort of expression to match a case and put the appropriate character there.
For example, lets say that the main function is defined.
int main () { cout << "hello"; return 0; }
With using expressions, I would be able to search for something like ) { and put a "\n" here for a newline and so on. The code would now look like:
1 2
int main ()
{ cout << "hello"; return 0; }
You guys get the point. Essentially that's what the program is going to do and I would this to be the most viable option. I don't think C++ has a standard regex library and I'm pretty sure that the string libraries cannot search for and replace content.
Anyways this is my dilemma. Hopefully I can get it to run ASAP.
You are doing one (or more) of the following wrong:
- you did not compile boost before copying out the include and lib directory files. You must do this first before boost::regex will work!
- you did not properly tell the compiler how to find the boost lib files. (Either copy them into your compiler's lib directory or use the -L command switch or set the $LD_LIBRARY_PATH environment variable.)
- you did not properly name the library file to link with. The documentation will say things like -lboost_regex but you must properly name an existing library file, like -lboost_regex-mgw44-1_42.
You may have already solved your problem. If not try this:
search your computer for a filename containing "boost_regex"
It should look something like this
libboost_regex-mgw45-1_44.a
and note the location.
Do the same for your headers--find out where they are. After you know where your libraries and headers are compile the program with a simple makefile like this:
There is no reason to compile it using a makefile, but at least you will know that you have the right headers and libraries.
Then re-post your question about how to use code blocks. People will be able to help you if you know where your headers and libraries are.
edit: forget the crap about using a makefile it will probably just confuse you more--just find your headers and libraries and repost your question when you know where they are are.
Thank you chwsks. I cannot find the file and I've lost all hope. :(
I've probably spent a good 12 hours trying to get Boost to run and I'm thinking it's not even worth my time. I'm going to try to find some other solutions. Boost doesn't like me. :(
I would not give up. Learning how to use external libraries is an important skill and it is only hard the first time. You obviously did not build boost correctly or you would be able to find the libraries. Start over ignore your IDE and just try to build boost. After you have successfully built boost try the example you posted above using the command line.
When you finished that re-post again when you know the location of your libraries and the headers. When you know where your libraries and headers are it is easy.
Do you know how to compile a program from the command line?
I think C/C++ libraries confuse a lot of developers especially if you come from other programming languages. E.g if you are from Java, you will find <filename>.jar most likely. Then all you got to do is during execution remember to set the classpath to point to the folder where <filename>.jar resides.
For C/C++ there is this .h files and then the binary .a or .so Why is it that way I don't know. All I know is we need those .h files so we can know the class functions and names to use in our program. Then during linking time, we need to find those .h implementation which is in the form of .a or .so
Therefore there are 2 components.
1. Where are all the .h files residing
2. Where are all the .a or .so files residing
Only when you get above 2 components sorted out will you "successfully" use those C/C++ libraries. A bit cumbersome I would say in comparison to Java just <filename>.jar and you are ready to go.
I think C/C++ libraries confuse a lot of developers
More like they confuse a lot of beginners.
That's not all. Once you've built the binary, you still need to know how to look for the dynamic libraries. Windows makes this pretty easy by letting you put them in the same directory as the main executable, but if you want to do the same under UNIX (maybe you don't want to put them in the standard system directory for some reason), you have to set LD_LIBRARY_PATH.
And don't get me started on Linux and binary compatibility or I'll have to get something stronger to drink.
BJam for Boost on Windows for GCC/MinGW/Cygwin doesn't work all that well. In the end, I ended up just compiling VC++ binaries and using the VC++ compiler while using GCC on all of my Linux hardware. In all actuality, it took me a grand total of ten minutes to set it all up. Try following Boost's instructions for BJam instead of Code::Blocks.
I think it might be the BJam problem because that is what the documentation says to use.
@chwsks
No I do not. I think I will have to read up on compiling using Command Line.
I guess my problem is that I don't really understand how a compiler "works". All I know is that I click a little icon (or F9) and hooray, I have a working program. I don't really understand the difference between a binary file and so on. This is my fault. :(
But I definitely think you are right. Learning to use libraries is very important especially when I move into higher level classes. At school we don't really go in depth on different topics and everyone is on their own. But thank you very much for the encouraging words. I think I will read up on compiling through the command line interface and keep you guys posted on the progress.