std::experimental::filesystem::v1::status link error even after -lstdc++ flag - g++

I try c++1z feature to use std::experimental::filesystem
After adding -lstdc++fs flag with g++, I can see that I am able to link std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts() with my program.
i.e I am not getting this error anymore
sdc.cpp:(.text+0x7e5): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
However, even after linking, I get the following error.
g++ -std=c++1z timer.cpp -lstdc++fs -O2 -I include -L lib -lOpenTimer -lpthread -o timer.out
lib/libOpenTimer.a(spef.cpp.o): In function spef::Spef::read(std::experimental::filesystem::v1::__cxx11::path const&)':
spef.cpp:(.text._ZN4spef4Spef4readERKNSt12experimental10filesystem2v17__cxx114pathE[_ZN4spef4Spef4readERKNSt12experimental10filesystem2v17__cxx114pathE]+0x2e): undefined reference tostd::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)'
lib/libOpenTimer.a(sdc.cpp.o): In function ot::sdc::home[abi:cxx11]()':
sdc.cpp:(.text+0x414): undefined reference tostd::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)'
sdc.cpp:(.text+0x7ab): undefined reference to std::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)'
lib/libOpenTimer.a(sdc.cpp.o): In functionot::sdc::SDC::read(std::experimental::filesystem::v1::__cxx11::path const&)':
sdc.cpp:(.text+0x2fa1): undefined reference to std::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)'
sdc.cpp:(.text+0x3084): undefined reference tostd::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)'
sdc.cpp:(.text+0x30db): undefined reference to std::experimental::filesystem::v1::current_path[abi:cxx11]()'
sdc.cpp:(.text+0x30f7): undefined reference tostd::experimental::filesystem::v1::absolute(std::experimental::filesystem::v1::__cxx11::path const&, std::experimental::filesystem::v1::__cxx11::path const&)'
sdc.cpp:(.text+0x3788): undefined reference to std::experimental::filesystem::v1::remove(std::experimental::filesystem::v1::__cxx11::path const&)'
lib/libOpenTimer.a(os.cpp.o): In functionot::user_homeabi:cxx11':
os.cpp:(.text+0x30d): undefined reference to `std::experimental::filesystem::v1::current_pathabi:cxx11'
collect2: error: ld returned 1 exit status
Any help to resolve this would be much appreciated.

It was me who posted the question. It seems like I was able to resolve it myself.
I added the -lstdc++fs at the end instead of middle and it started working.
Here's the updated command
g++ -std=c++1z timerapp.cpp -O2 -I include -L lib -lOpenTimer -lpthread -o timer.out -lstdc++fs
compared to the previous command
g++ -std=c++1z timerapp.cpp -lstdc++fs -O2 -I include -L lib -lOpenTimer -lpthread -o timer.out
Don't know why some linking flags are expected to be added in the end though.

-lstdc++fs flag should be passed at the tail of linker command.
With CMake:
This works:
target_link_libraries(your_project stdc++fs)
And this won't:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -lstdc++fs")

Related

Difficulty in linking FFTW library with gfortran

I have a c++ program, which uses the FFTW3 library, which I would like to translate to Fortran. I am using Ubuntu 22.04.1.
I installed the FFTW3 library as detailed in Installation on UNIX
The c++ main program is named ksbenchmark.cpp and, using g++, I compile it and link it (to the math and fftw3 libraries) with
g++ -o my_executable.out ksbenchmark.cpp -lm -lfftw3
which works great.
I have translate the c++ code in Fortran, the source file being named ksbenchmrk.f90.
If I issue
gfortran ksbenchmark.f90 -lfftw3 -lm
I get error messages
/usr/bin/ld: /tmp/cca2xMGa.o: in function `ksintegrate_':
ksbenchmark.f90:(.text+0x59): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x94): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksbenchmark.f90:(.text+0xcf): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x4de): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x5db): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x626): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0x780): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksbenchmark.f90:(.text+0xa1c): undefined reference to `dfftw_execute_'
collect2: error: ld returned 1 exit status
I have spent the afternoon reading about it, and it seems I may have to use -I and -L flags such as
gfortran test.f90 -L/new/path/to/lib -I/new/path/to/include -lfftw3 -lm
as illustrated in the post Problems linking FFTW with gfortran (symbol(s) not found for architecture x86_64).
The first question is, what paths to use?
I can find files referring to fftw3 in /usr/local/lib as well as in /usr/local/include, but the attempt
gfortran ksbenchmark.f90 -L/usr/local/lib -I/usr/local/include -lfftw3 -lm
returns the same error as before
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
/usr/bin/ld: /tmp/ccW2DYGP.o: in function `ksintegrate_':
ksintegrate.f90:(.text+0x62): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksintegrate.f90:(.text+0x9d): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksintegrate.f90:(.text+0xd8): undefined reference to `dfftw_plan_dft_1d_'
/usr/bin/ld: ksintegrate.f90:(.text+0x4df): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0x5f7): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0x643): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0x79d): undefined reference to `dfftw_execute_'
/usr/bin/ld: ksintegrate.f90:(.text+0xa5b): undefined reference to `dfftw_execute_'
collect2: error: ld returned 1 exit status
I am unable to understand which paths to the library are to be used.
How to find where the library is saved?
Why does not g++ need any paths to the library?
I apologise for how trivial the question might seem, I am a total newbie can ensure I put a significant effort in trying to sort this out. Any hint would be most appreciated, thanks
EDIT
Following Vladimir F Героям слава's advice, I tried using the nm command to verify the library contains what is expected to.
In /usr/local/lib
I found libfftw3.a and libfftw3.la files.
Issuing nm libfftw3.a I get quite a long list.
I tried looking for one of the commands I get an error about, dfftw_plan_dft_1d
nm -S libfftw3.a | grep dfftw_plan_dft_1d
and indeed it returns hits
00000000000003a0 0000000000000026 T _Z18dfftw_plan_dft_1d_PP11fftw_plan_sPiPA2_dS4_S2_S2_
0000000000002df0 0000000000000026 T _Z19dfftw_plan_dft_1d__PP11fftw_plan_sPiPA2_dS4_S2_S2_

Print library full-path found with target_link_libraries

In the CMake I have:
target_link_libraries(${TESTNAME} ${CMAKE_DL_LIBS})
I think libdl.so is found because the linker does not complain that: " cannot find -lld".
Still, I get the error:
[ 50%] Linking CXX executable test1
/opt/poky/2.7.3/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/8.3.0/real-ld: /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libport.so: undefined reference to `dlopen'
/opt/poky/2.7.3/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/8.3.0/real-ld: /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libport.so: undefined reference to `dlclose'
/opt/poky/2.7.3/sysroots/x86_64-pokysdk-linux/usr/libexec/aarch64-poky-linux/gcc/aarch64-poky-linux/8.3.0/real-ld: /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libport.so: undefined reference to `dlerror'
Because I am cross-compiling, I think it might have linked the wrong file or the libdl.so might be broken.
How can I find out which file was linked by target_link_libraries? I need a full path to the file.
EDIT:
Output of make VERBOSE=1:
/opt/poky/2.7.3/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -march=armv8-a+crc --sysroot=/opt/poky/2.7.3/sysroots/aarch64-poky-linux --sysroot=/opt/poky/2.7.3/sysroots/aarch64-poky-linux -O2 -pipe -g -feliminate-unused-debug-types -O3 -DNDEBUG -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed CMakeFiles/test1.dir/test1.cpp.o CMakeFiles/test1.dir/__/animateEyes.cpp.o CMakeFiles/test1.dir/__/lcd_graphics.cpp.o CMakeFiles/test1.dir/__/trajGen.cpp.o CMakeFiles/test1.dir/lcd.cpp.o -o test1 -Wl,-rpath,/usr/lib/collar/engine -ldl /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/collar/engine/libuobject.so ../../../lib/libgtest.a ../../../lib/libgmock.a ../../../lib/libgtest_main.a /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libsched.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libserialize.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libport.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_regex-mt.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_signals-mt.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_filesystem-mt.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_thread-mt.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_date_time-mt.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_chrono-mt.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_system-mt.so /opt/poky/2.7.3/sysroots/aarch64-poky-linux/usr/lib/libboost_atomic-mt.so ../../../lib/libgtest.a -lpthread

How to fix /usr/bin/ld: cannot find -lboost_python

I just installed boost.python following the instructions on https://www.boost.org/doc/libs/1_69_0/libs/python/doc/html/building/no_install_quickstart.html
but when I try to run the code
bjam toolset=gcc --verbose-test test
it throws:
...found 23 targets...
...updating 6 targets...
gcc.link.dll extending.so
/usr/bin/ld: cannot find -lboost_python
collect2: error: ld returned 1 exit status
"g++" -o "extending.so" -Wl,-h -Wl,extending.so -shared -Wl,--start-group "extending.o" -Wl,-Bstatic -Wl,-Bdynamic -lboost_python -ldl -lpthread -lutil -Wl,--end-group -fPIC -g
...failed gcc.link.dll extending.so...
...skipped <p.>test_ext for lack of <p.>extending.so...
gcc.link test_embed
/usr/bin/ld: cannot find -lboost_python
collect2: error: ld returned 1 exit status
"g++" -L"/usr/lib" -L"/usr/lib/python2.7/config" -Wl,-rpath -Wl,"/usr/lib" -Wl,-rpath -Wl,"/usr/lib/python2.7/config" -o "test_embed" -Wl,--start-group "embedding.o" -Wl,-Bstatic -Wl,-Bdynamic -lboost_python -ldl -lpthread -lutil -lpython2.7 -Wl,--end-group -fPIC -g
...failed gcc.link test_embed...
...skipped <p.>test_embed.run for lack of <p.>test_embed...
...failed updating 2 targets...
...skipped 4 targets...
Anyone knows how to solve it? I only want boost to use boost.python.
Thanks
It's a linker error. Probably the lib file is under a different name, so have to create a symbolic link manually.
Search and locate the "libboost_pythonXX.so" file in the usr/lib directory
XX will match the python version with which you configured boost while building, From the exception thrown you probably configured it with python2.7, so the file probably will be named as libboost_python27.so
and then create a symbolic link :
sudo ln -s "libboost_pythonXX.so" libboost_python.so
You can use this link for reference.
https://github.com/BVLC/caffe/issues/4843
It helped me to solve the error for me.

/usr/bin/ld: cannot find -lpq

I want connect to postgresql by libpqxx (C++)
When running g++ with -lpq I got this error:
[michael#michael cpp]$ g++ Store.cpp -lpqxx -std=c++11 -lpq
/usr/bin/ld: cannot find -lpq collect2: error: ld returned 1 exit
status
When I remove -lpq it's run well and work, I want to know why with -lpq it's not work and how fix it.
Thanks, Michael.

compile object code in linux error (.text+0x20): undefined reference to `main'

im triying to compile a object from the source
http://xeat-engine.googlecode.com/svn/trunk/
using the code
g++ -c wx-config --cxxflags main.cpp
g++ -o main main.o wx-config --libs
and obtain the error
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function _start':
(.text+0x20): undefined reference tomain'
collect2: error: ld returned 1 exit status
please help me to fix the problem
What could I do?
IS A CAPTURE FOR MAIN.CPP
http://i.stack.imgur.com/TziYb.jpg
You're missing:
wxIMPLEMENT_APP(xeatengine_guiApp);
which will be expanded into a valid main() function.
NOTE: the trailing semicolon is necessary...
See also:
wxDECLARE_APP(xeatengine_guiApp);