c++ boost::filesystem undefined reference to `boost::filesystem3::path::root_name() const'
33,564
You have to link with -lboost_filesystem -lboost_system
. Boost filesystem is not a header-only library; rather, it depends on compiled components.
Author by
KG6ZVP
I host my own git here: https://gitlab.mccollum.enterprises/smccollum/
Updated on July 09, 2022Comments
-
KG6ZVP almost 2 years
I keep running across errors when trying to compile code which utilizes the boost::filesystem library. I don't understand any of the compiler outputs I am getting. Here is my code copied from http://www.highscore.de/cpp/boost/dateisystem.html#dateisystem_pfadangaben:
#include <boost/filesystem.hpp> #include <iostream> int main(){ boost::filesystem::path p("C:\\Windows\\System"); std::cout << p.root_name() << std::endl; std::cout << p.root_directory() << std::endl; std::cout << p.root_path() << std::endl; std::cout << p.relative_path() << std::endl; std::cout << p.parent_path() << std::endl; std::cout << p.filename() << std::endl; }
I have Ubuntu 11.10 and I have installed libbost-dev and g++. This is what the terminal looks like:
sam@sam-MT6707:~/Dokumente/Programming/Projekte/FTP-abgleicher$ g++ -o pr3 pr3.cpp /tmp/ccrN7yHl.o: In function `main': pr3.cpp:(.text+0x3b): undefined reference to `boost::filesystem3::path::root_name() const' pr3.cpp:(.text+0x7e): undefined reference to `boost::filesystem3::path::root_directory() const' pr3.cpp:(.text+0xc1): undefined reference to `boost::filesystem3::path::root_path() const' pr3.cpp:(.text+0x104): undefined reference to `boost::filesystem3::path::relative_path() const' pr3.cpp:(.text+0x147): undefined reference to `boost::filesystem3::path::parent_path() const' pr3.cpp:(.text+0x18a): undefined reference to `boost::filesystem3::path::filename() const' pr3.cpp:(.text+0x1e8): undefined reference to `boost::filesystem3::path::stem() const' pr3.cpp:(.text+0x22b): undefined reference to `boost::filesystem3::path::extension() const' /tmp/ccrN7yHl.o: In function `__static_initialization_and_destruction_0(int, int)': pr3.cpp:(.text+0x364): undefined reference to `boost::system::generic_category()' pr3.cpp:(.text+0x36e): undefined reference to `boost::system::generic_category()' pr3.cpp:(.text+0x378): undefined reference to `boost::system::system_category()' /tmp/ccrN7yHl.o: In function `boost::filesystem3::path::codecvt()': pr3.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x7): undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()' collect2: ld gab 1 als Ende-Status zurück ^Translation of last line: ld returned an end status of 1
What am I doing wrong?
-
KG6ZVP over 12 yearsDo you mean that I need to change my command line to: g++ -lboost_filesystem -o pr3 pr3.cpp
-
KG6ZVP over 12 yearsI added -lboost_filesystem to the end of my command line: g++ -o pr3 pr3.cpp -lboost_filesystem However, I now get this output: /usr/bin/ld: /tmp/ccKa219G.o: undefined reference to symbol 'boost::system::system_category()' /usr/bin/ld: note: 'boost::system::system_category()' is defined in DSO /usr/lib/libboost_system.so.1.46.1 so try adding it to the linker command line /usr/lib/libboost_system.so.1.46.1: could not read symbols: Invalid operation collect2: ld returned an end status of 1
-
Kerrek SB over 12 years@KG6ZVP: Also add
-lboost_system
. -
Beached about 12 yearsboost.org/doc/libs/1_47_0/more/getting_started/… under header only libraries will tell you which ones need library references.
-
Tanner Strunk about 6 years@Beached I was literally just about to ask for a reference for all this boost compilation stuff when I saw your link. Thanks!
-
RJTK over 5 yearsWith cmake you can do
find_package(Boost REQUIRED COMPONENTS filesystem)