Problems linking on Linux

I’m not very experienced at Linux development, so please be kind :slight_smile:

I’m trying to link with libtiff.a (static library) which is in /usr/local/lib

I have this in my CMakeLists.txt:

# Link with other targets.
target_link_libraries(DeepSkyStacker PRIVATE
    Qt6::Core
    Qt6::Widgets
    Qt6::Network
	DeepSkyStackerKernel
    libraw
    ZClass
)
if(WIN32)
target_link_libraries(DeepSkyStacker PRIVATE
    libtiff
)
endif()

if(WIN32)
set(DEBUG_DEPENDENCIES exiv2d zlibstaticd)
set(RELEASE_DEPENDENCIES exiv2 zlibstatic)
else()
set(DEBUG_DEPENDENCIES libtiff.a exiv2 expat libz.a)
set(RELEASE_DEPENDENCIES libtiff.a exiv2 expat libz.a)
endif()

set(ADDITIONAL_LIBRARY_DEPENDENCIES
    "$<$<CONFIG:Debug>:${DEBUG_DEPENDENCIES}>"
    "$<$<CONFIG:Release>:${RELEASE_DEPENDENCIES}>"
    "cfitsio"
)

if(WIN32)
set(ADDITIONAL_LIBRARY_DEPENDENCIES ${ADDITIONAL_LIBRARY_DEPENDENCIES}
    user32
    psapi
    htmlhelp
)
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}")

when I try to link I get:

[32/32] Linking CXX executable DeepSkyStacker/DeepSkyStacker
FAILED: DeepSkyStacker/DeepSkyStacker 
: && /usr/bin/c++ -g  DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/DeepSkyStacker_autogen/mocs_compilation.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/About.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/ExplorerBar.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/processingcontrols.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/ProcessingDlg.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/ProcessingSettingsDlg.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/RGBTab.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/SavePicture.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/StarMaskDlg.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/AskRegistering.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/RegisterSettings.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/AlignmentParameters.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/CometStacking.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/IntermediateFiles.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/OutputTab.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/PostCalibration.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/RawDDPSettings.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/ResultParameters.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/StackingParameters.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/StackSettings.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/BackgroundOptions.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/BatchStacking.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/CheckAbove.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/DropFilesDlg.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/ImageProperties.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/picturelist.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/RecommendedSettings.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/RenameGroup.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/SaveEditChanges.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/StackingDlg.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/StackRecap.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/lowerdockwidget.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/BaseDialog.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/DeepSkyStacker.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/Delaunay.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/editstars.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/progressdlg.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/selectrect.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/toolbar.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/__/Tools/imageview.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/__/Tools/QElidedLabel.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/__/Tools/QLinearGradientCtrl.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/DeepSkyStacker_autogen/O3VI4VFR3H/qrc_translations.cpp.o DeepSkyStacker/CMakeFiles/DeepSkyStacker.dir/DeepSkyStacker_autogen/EWIEGA46WW/qrc_resources.cpp.o -o DeepSkyStacker/DeepSkyStacker  -Wl,-rpath,/opt/Qt/6.8.0/gcc_64/lib:  DeepSkyStackerKernel/libDeepSkyStackerKernel.a  LibRaw/buildfiles/liblibraw.a  ZClass/libZClass.a  -Wl,-Bstatic  -ltiff  -Wl,-Bdynamic  -lexiv2  -lexpat  -Wl,-Bstatic  -lz  -Wl,-Bdynamic  -lcfitsio  /opt/Qt/6.8.0/gcc_64/lib/libQt6Widgets.so.6.8.0  /opt/Qt/6.8.0/gcc_64/lib/libQt6Gui.so.6.8.0  /usr/lib/x86_64-linux-gnu/libGLX.so  /usr/lib/x86_64-linux-gnu/libOpenGL.so  /opt/Qt/6.8.0/gcc_64/lib/libQt6Network.so.6.8.0  /opt/Qt/6.8.0/gcc_64/lib/libQt6Core.so.6.8.0  -llibtiff  -Wl,-rpath-link,/opt/Qt/6.8.0/gcc_64/lib && :
/usr/bin/ld: cannot find -llibtiff: No such file or directory
/usr/bin/ld: note to link with /usr/local/lib/libtiff.a use -l:libtiff.a or rename it to liblibtiff.a
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

I imagine I’ve made a classic beginner’s mistake, but what is it please?

Thanks
David

It looks like you’re building GitHub - deepskystacker/DSS: DeepSkyStacker
This project uses some unconventional techniques in their CMakeLists files.
I would try adding to the top level CMakeLists.txt like

add_subdirectory(LibTiff)

before the line 116 add_subdirectory(DeepSkyStacker)

But to use system libtifff, add

find_library(libtiff NAMES tiff REQUIRED)

In general in CMake projects one might use https://cmake.org/cmake/help/latest/module/FindTIFF.html

As I’m new to CMake it is quite likely that I’m not aware of “best practice”. Yes, I wrote all the CMakeLists.txt files you see in that GitHub project.

The linux branch is the one I am working on - CMake is a very recent thing for us.

I attach the latest CMakeLists.txt

Any suggestions for improvement most welcome - though I’m not clear what that find_library call buys me.
CMakeLists.txt (13.3 KB)

And here’s the top-level CMakeLists.txt
CMakeLists.txt (4.7 KB)

Here’s what the configure output looks like:

1> CMake generation started for configuration: 'Qt-Debug-Linux'.
1> Found cmake executable at /usr/bin/cmake.
1> /usr/bin/cmake -G "Ninja"   -DCMAKE_PREFIX_PATH:STRING="/opt/Qt/6.8.0/gcc_64" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_SYSTEM_NAME:STRING="Linux"   /home/amonra/.vs/DSS/CMakeLists.txt;
1> [CMake] WIN32 is set to , LINUX is set to 1
1> [CMake] System Name is: Linux, prefix path: /opt/Qt/6.8.0/gcc_64
1> [CMake] x64 architecture in use
1> [CMake] CMAKE_SOURCE_DIR: /home/amonra/.vs/DSS
1> [CMake] CMAKE_VS_PLATFORM_NAME: x64
1> [CMake] CMAKE_BUILD_TYPE: Debug
1> [CMake] CMAKE_INSTALL_PREFIX set to: /home/amonra/.vs/DSS/Linux/x64/Debug
1> [CMake] -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
1> [CMake] -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
1> [CMake] Configuring project: DeepSkyStacker
1> [CMake] -- Link libraries: Qt6::CoreQt6::CoreQt6::WidgetsQt6::NetworkDeepSkyStackerKernellibrawZClass$<$<CONFIG:Debug>:tiff.aexiv2.aexpat.az.acfitsio.a>$<$<CONFIG:Release>:tiff.aexiv2.aexpat.az.acfitsio.a>
1> [CMake] Qt Deploy Bin Dir: .
1> [CMake] Qt Deploy Lib Dir: .
1> [CMake] Target filename:$<TARGET_FILE_NAME:DeepSkyStacker>
1> [CMake] executable_path: ./$<TARGET_FILE_NAME:DeepSkyStacker>
1> [CMake] deploy tools options arg: .

ARRGGH!

The problem came from the CMakeLists.txt for one of the static libs which contained:

target_link_libraries(${PROJECT_NAME} PUBLIC libraw libtiff ZClass )

David