5

Trying to run the following:

        #include<iostream>
        #include<boost/filesystem/operations.hpp>

        namespace bfs=boost::filesystem;
        int main()
        {
        bfs::path p("second.cpp");
        if(bfs::exists(p))
        std::cout<<p.leaf()<<std::endl;
        }

I got some errors in cygwin so I decided to try out netbeans, and used the following as a guide. I added all links and the following for filesystem Project -> properties -> Linker ->Libraries -> Add option -> Other -> -lfile_system as noted here. I have run a separate test using #include<boost/any.hpp> so I am not currently doubting that my boost is not installed correclty.

It seems weird to me that it is "file_system", so I also tried "filesystem" but to no avail.

When i hold Ctrl and click on #include<boost/filesystem/operations.hpp> my netbeans brings up my operations.hpp file so it seems okay (linked properly internally that it can "see" what I want it to see).


The solution to installing boost came in the following form: 1 - If you have any path variables that are being used for Visual Studio you should temporarily change the variable during installation. This is a good guide. Once that is done, this is one step completed.

2 - Download and install MinGW. This is a very easy process and you can find the installer files here.

Once you have done these things (if you are in the same situation as me), you will now be able to properly install boost.

Horay!

6
  • 3
    -lfile_system is wrong. Usually, it is -lboost_filesystem or -lboost_filesystem-mt, check your lib directory. You might also need -lboost_system.
    – Jesse Good
    May 2, 2013 at 1:43
  • What are the errors you get?
    – 43l0v3k
    May 2, 2013 at 11:40
  • Jesse - tried those. Not working still.
    – jason m
    May 4, 2013 at 1:53
  • 1
    Did you read the error message? Boost.Filesystem V3 and later requires std::wstring support. Does your standard library provide std::wstring?
    – Sam Miller
    May 4, 2013 at 18:19
  • 1
    You should determine the answer to the question that @Sam posted. Make sure you are using gcc4-g++ (rather than gcc-g++), and also the latest libstdc++. You could try compiling a very simple test: #include <string> int main(int argc, char *argv[]) { std::wstring w; return 0; }
    – Markku K.
    May 8, 2013 at 16:34

3 Answers 3

8

Using Boost with cygwin step by step

Create a new Project

enter image description here

It is better to take the names given here in this tutorial exactly. Later ask: It does not work, can then be easier to find.

I do not think I need to mention all T:\ must of course be replaced with your drive.

Project Name : Boost-cyg-Test

enter image description here

Now your Project should look like

enter image description here

Open main.cpp
Overwrite the generated code with the following. We want to that, first of all everything works without error.

Therefore, please do not use your own special code.
It is difficult to find a fault. Then told after several ask, to get:
I have used my own code

#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;

int main()
  {
    path p("second.cpp");
      if (exists(p)) { std::cout<<p.leaf()<<std::endl; }
  }

In this section we assume that "boost" is already compiled.

goto Tools -> Options

Your C++ Code Assistance options should look something like this.

enter image description here

If this is not so, we should let Netbeans create that for us.

enter image description here

Add New Tool Collection

enter image description here

After we have completed this dialog with OK, we should find the settings shown above. ( C++ Code Assistance options).

Copy all libs into the right place

Let's create a new folder 'boost'.

enter image description here

With a search tool, search in your compiled Boost folder for *.a
My Boost is compiled with the shared option so we find :

enter image description here

For our short App. we need only 2 files.

libboost_filesystem-gcc45-mt-d-1_53.dll.a
libboost_system-gcc45-mt-d-1_53.dll.a

But if we're at it to copy two files, we can copy all files.
So mark all found .a files and copy them into the directory just created
T:\cygwin\lib\boost .

Now we do the same with our .dll files.
Mark all .dll files and copy it in your ?:\cygwin\bin directory.
If you only have compiled static librarys, you can skip this point.

enter image description here

Now it's time to modify our project settings.
As you can see i put my source Boost folder into cygwin

enter image description here

and

enter image description here

As we have already noted above, we need two .a files.
with Add Library navigate to T:\cygwin\lib\boost and select

libboost_filesystem-gcc45-mt-d-1_53.dll.a
libboost_system-gcc45-mt-d-1_53.dll.a

Now you'll notice that this name was shortened by netbeans to:

boost_filesystem-gcc45-mt-d-1_53.dll
boost_system-gcc45-mt-d-1_53.dll

enter image description here

This is somewhat confusing. It looks as if a .dll is standing here. But it is really a .a file.

Set a breakpoint in main.cpp. Now we start debug.

enter image description here

I have marked the important part, the two libs, with an arrow.
All libs are found and after make has finished, stops at the breakpoint.

The output:

enter image description here

Build Boost for Cygwin

For all who want to create boost with shared library itself.

Download boost_1_53_0.zip

Create a folder in your ?:\cygwin directory.
boost_1_53_0

enter image description here

Extract the zip file into that directory.
It should look like:

enter image description here

open a cmd window, cd to boost_1_53_0 directory.
To have a clean build we need a PATH that have only the cygwin home and bin.
In the cmd type.

SET PATH=T:\cygwin;T:\cygwin\bin 

and test the path.

PATH

enter image description here

Type

bootstrap.bat

enter image description here

Type

.\b2 --build-dir=T:\boost-cyg toolset=gcc variant=debug link=shared runtime-link=shared

After some time the build is finished.
Now you have the same environment that we have used in the tutorial.

If you get a Error : gcc not found
copy (not rename) in ?:\cygwin\bin folder, for example : (names may differ).
i686-pc-cygwin-gcc-4.5.3.exe to gcc.exe
and
i686-pc-cygwin-g++-4.exe to g++.exe

Hope it helps you.

3
  • i did that. ok new issue: i don't have libboost_(etc).dll, but i have cygboost_(etc).dll that being said i do not have filesystem. this seems odd. i am trying your boost installation instructions now to see if this solves the problem.
    – jason m
    May 11, 2013 at 16:41
  • when I run the cmd you write above I get the error that will be posted above as a screenshot (appended to my question)
    – jason m
    May 11, 2013 at 17:31
  • cygwin make.exe here make-cyg.zip .
    – moskito-x
    May 20, 2013 at 2:07
0

Could you paste the error you get when compiling ? I am not used to compile programs in a Windows environment, but I think as Jesse Good suggested in a comment that you have a linker error.

You may solve it by using -lboost_filesystem instead of lfile_system.

To find out how your libs are called, you get the name of your lib (on my unix environment I have libboost_filesystem.so), strip the "lib" prefix and the ".so" or ".a" suffix (must be different in a Windows environment).

2
  • where would these libboost_filesystem.so files be found? i do not see these in my ~/usr/include/ where exactly would they be?
    – jason m
    May 4, 2013 at 1:54
  • The libs (used by the linker) are located in /usr/lib or /usr/local/lib. The headers (those you include with #include) are located in /usr/include or /usr/local/include May 5, 2013 at 15:45
0

if your boost installation is correct and you are sure about it then for Unable to resolve identifier try Code Assistance->Reparse Project from context menu of the project. It tries to recover broken code model by reparsing project from scratch. if that didn't workout try closing IDE and removing code model cache.

p.s. do you have compilation errors?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.