4

Merry Christmas, everyone.

Yesterday I download the Boost library. i use CodeBlocks (with Mingw32 gcc V4.4.1) to compile it. The bjam command line is : bjam install --toolset=gcc--prefix="C:\zjc\PluginFramework\boost_1_42_0" --build-type=complete. and it is successful. and i want to test the library. i write some code as follow:

#include <stdlib.h>
#include <iostream>
using std::cout;
using std::wcout;
using std::endl;
#include <string>
using std::string;
using std::wstring;

#include <boost/algorithm/string.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/format.hpp>

int main(int argc, char* argv[])
{
    // ANSI character format
    cout << boost::format( "%1% %2%" ) % "Hell" % "Low" <<endl;
    string s1 = boost::str( boost::format( "%2% %1%" ) % "Hell" % "Low" );
    cout << s1 << endl;
    // UNICODE character format
    wcout << boost::wformat( L"%s %X" ) % L"-1 is" % -1 << endl;
    wstring s2 = boost::str( boost::wformat( L"%2$s %1$.2f" ) % 3.141592 % L"Version" );
    wcout << s2 << endl;
    // get the path of application(ANSI character set), note:boost::filesystem::path
    string AnsiPath = boost::filesystem::initial_path<boost::filesystem::path>().string();
    cout<<AnsiPath<<endl;
     // get the path of application(unicode character set), note:boost::filesystem::wpath
    wstring UnicodePath = boost::filesystem::initial_path<boost::filesystem::wpath>().string();
    wcout<<UnicodePath<<endl;
    system("PAUSE");
    return 0;
}

one compile error occur: obj\Debug\main.o:C:\zjc\PluginFramework\boost_1_42_0\include\boost-1_42\boost\filesystem\operations.hpp|530|undefined reference to `boost::filesystem::detail::get_current_path_api(std::string&)'| I have added the the library at linker option:

boost_system-mgw44-mt-d-1_42.lib

libboost_system-mgw44-sd-1_42.lib

boost_system-mgw44-d.lib

boost_system-mgw44-d-1_42.lib

boost_system-mgw44-mt-d-1_42.lib

the macros:

BOOST_ALL_DYN_LINK

BOOST_SYSTEM_NO_LIB

BOOST_SYSTEM_NO_DEPRECATED

_DEBUG

_CONSOLE

BOOST_FILESYSTEM_VERSION

BOOST_FILESYSTEM_DYN_LINK

BOOST_LIB_DIAGNOSTIC

I search the internet.the solution is linking the boost filesystem library.but i have linked the library. My Environment: Win 7 Home version, Code::Blocks V 10.05.

1 Answer 1

10

The Boost filesystem library is one of the linkable (and not header only) libraries included. Just add "boost_filesystem" before "boost_system".

If everything is set up the right way, you shouldn't have to add the libraries yourself: Don't set BOOST_SYSTEM_NO_LIB/BOOST_FILESYSTEM_NO_LIB unless you really have to. If it isn't set, the headers should handle the dependencies for you.

The macros with BOOST_..._DYN_LINK will cause the headers to try to link the shared libraries (which you deactivated with the other macros).

Just one more note: If you'd like to add the libs by hand. Don't mix them and only add one variant each, which you need, and pick the right one (e.g. multithreaded debug "mt-d").

Your Answer

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

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