jeremy-rifkin / cpptrace

Simple, portable, and self-contained stacktrace library for C++11 and newer
MIT License
642 stars 67 forks source link

no system wide install test #96

Closed Gussak closed 6 months ago

Gussak commented 6 months ago

hi!

I am still trying it, I would like to see it working in one project for now, I compiled it and it created libcpptrace.a, but no matter what param I pass to /usr/bin/c++

I always get this:

ld.lld: error: unable to find library -l:/AbsolutePathToTheLib/libcpptrace.a ld.lld: error: unable to find library -lcpptrace ld.lld: error: unable to find library -l:libcpptrace.a ld.lld: error: unable to find library -l:./libcpptrace.a ld.lld: error: unable to find library -l:./RelativePathToLib/libcpptrace.a

also, I saw there is nothing about libcpptrace.a, only about libcpptrace.so in the readme.md and the instructions are all for system wide right?

PS.: ubuntu 22.04

jeremy-rifkin commented 6 months ago

Hi Gussak, how are you compiling and how did you install? Maybe try building cpptrace with -DBUILD_SHARED_LIBS=On, which should probably be mentioned in the system wide install instructions.

A working example for a system wide install is at https://github.com/jeremy-rifkin/cpptrace/tree/main/test/findpackage-integration and https://github.com/jeremy-rifkin/cpptrace/blob/f879cd8b7b1a1d5ea1a3384df861e865a70e1151/.github/workflows/cmake-integration.yml#L37-L48

jeremy-rifkin commented 6 months ago

Testing locally I was able to get it working with cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/foo and then cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/tmp/foo for the demo program, for both shared and static. As well as the more manual method of:

g++ main.cpp -I /tmp/foo/include -L /tmp/foo/lib/ -lcpptrace -ldwarf -lzstd -lz -g

for static and for shared:

g++ main.cpp -I /tmp/foo/include -L /tmp/foo/lib/ -lcpptrace -Wl,-rpath /tmp/foo/lib -g
Gussak commented 6 months ago

sorry, my mistake, I needed to pass ../pathToLib/libcpptrace.a instead of ./ as the build happens at theproject/build and not at theproject path, and pathToLib is at theproject path (but I think I also needed to use -L to that path, need time to test w/o it..)

now I just have to fix dwarf simbols missing like ld.lld: error: undefined symbol: dwarf_errno

thx!

jeremy-rifkin commented 6 months ago

Glad you got it working. Libdwarf.a should be built during cpptrace’s building, unless configured to use an external libdwarf install, and hopefully linking against libdwarf.a should fix that. Similarly libzstd.a should be built and then libz should already be on your system.

Gussak commented 6 months ago

Libdwarf.a should be built during cpptrace’s building,

I saw it downloads from https://github.com/facebook/zstd, for dwarf too? but anyway, I went into synaptic and installed a lot of dwarf related things like libs and dev packages, and I still get these errors below (sorry, I am not a very good documentation reader..)

ld.lld: error: undefined symbol: dwarf_errno
>>> referenced by symbols_with_libdwarf.cpp
>>>               symbols_with_libdwarf.cpp.o:(cpptrace::detail::libdwarf::handle_dwarf_error(Dwarf_Debug_s*, Dwarf_Error_s*)) in archive ../thirdpartylibs/libcpptrace.a

ld.lld: error: undefined symbol: dwarf_errmsg
>>> referenced by symbols_with_libdwarf.cpp
>>>               symbols_with_libdwarf.cpp.o:(cpptrace::detail::libdwarf::handle_dwarf_error(Dwarf_Debug_s*, Dwarf_Error_s*)) in archive ../thirdpartylibs/libcpptrace.a

ld.lld: error: undefined symbol: dwarf_siblingof_b

sorry asking these basic things here but I dont get why these system things that should be working by default just doesnt work.. /usr/bin/c++ -fPIC -Wall -Wextra -Warray-bounds=2 -Wcast-qual -Wcatch-value=3 -Wdouble-promotion -Wduplicated-cond -Wextra-semi -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wnoexcept -Woverflow -Woverloaded-virtual -Wpessimizing-move -Wpointer-arith -Wredundant-decls -Wshift-overflow -Wstrict-null-sentinel -Wstringop-overflow=2 -Wundef -Wunused-const-variable=1 -Wunused-macros -Wvla -Wfloat-conversion -Wenum-conversion -Wsuggest-override -Wsign-promo -Wold-style-cast -Wshadow -Wduplicated-branches -Wno-maybe-uninitialized -std=c++20 -pedantic -fvisibility=hidden -fvisibility-inlines-hidden -ggdb3 -O0 -fno-omit-frame-pointer -lboost_stacktrace_backtrace -L../thirdpartylibs/ -I../thirdpartylibs/cpptrace/include -lcpptrace -L/usr/lib/x86_64-linux-gnu/ -l:/usr/lib/x86_64-linux-gnu/libdwarf.a -fuse-ld=lld -Wl,--no-undefined -shared -Wl,-soname,libArxIO.so.0 -o libArxIO.so.1.2.9999.9999 CMakeFiles/ArxIO.dir/src/lib/ArxIO.cpp.o CMakeFiles/_arx_arxtool_ArxIO_common.dir/src/io/Blast.cpp.o CMakeFiles/common.dir/src/io/log/ConsoleLogger.cpp.o CMakeFiles/common.dir/src/io/log/LogBackend.cpp.o CMakeFiles/common.dir/src/io/log/Logger.cpp.o CMakeFiles/common.dir/src/io/log/ColorLogger.cpp.o CMakeFiles/common.dir/src/io/fs/FilePath.cpp.o CMakeFiles/common.dir/src/io/fs/FileStream.cpp.o CMakeFiles/common.dir/src/io/fs/Filesystem.cpp.o CMakeFiles/common.dir/src/io/fs/SystemPaths.cpp.o CMakeFiles/common.dir/src/io/fs/FilesystemPOSIX.cpp.o CMakeFiles/common.dir/src/platform/Environment.cpp.o CMakeFiles/common.dir/src/platform/OS.cpp.o CMakeFiles/common.dir/src/platform/Platform.cpp.o CMakeFiles/common.dir/src/platform/Process.cpp.o CMakeFiles/common.dir/src/platform/ProgramOptions.cpp.o CMakeFiles/common.dir/src/platform/Time.cpp.o CMakeFiles/common.dir/src/util/Number.cpp.o CMakeFiles/common.dir/src/util/String.cpp.o /usr/lib/x86_64-linux-gnu/librt.a /usr/lib/x86_64-linux-gnu/libz.so

I keep getting this error:

ld.lld: error: unable to find library -l:/usr/lib/x86_64-linux-gnu/libdwarf.a

the libcpptrace error is gone, now the system wide lib installed and explicitly configured to be used is just totally ignored, and these things are out of my grasp :(

jeremy-rifkin commented 6 months ago

If you follow the instructions to build cpptrace and run make install (or the equivalent for another build system) it should handle the building and installation of libdwarf and zstd for you. If you want to build libdwarf yourself you can do so from https://github.com/davea42/libdwarf-code. -l:/usr/lib/x86_64-linux-gnu/libdwarf.a This libdwarf most likely isn't the correct libdwarf.

But, I'd recommend just going through the cpptrace build/install and then g++ main.cpp -I /tmp/foo/include -L /tmp/foo/lib/ -lcpptrace -ldwarf -lzstd -lz -g.

Gussak commented 6 months ago

oh... now I get it, it needs a custom (or a different) libdwarf, and not what comes with ubuntu 22.04 ! thx, I will try again as soon I can.