Saturday, June 4, 2022

[SOLVED] ld.lld: error: could not open 'libLIBCMTD.a': No such file or directory

Issue

I recently installed vspkg and tried to build my c++ application with libcurl using command vcpkg.exe install curl:x64-windows-static

After i tried to compile it, i got an error on linking stage

ld.lld: error: could not open 'libLIBCMTD.a': No such file or directory
ld.lld: error: could not open 'libOLDNAMES.a': No such file or directory
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\testEnv.dir\build.make:140: C:/Users/Administrator/libtestEnv.dll] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/testEnv.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/testEnv.dir/rule] Error 2
mingw32-make: *** [Makefile:123: testEnv] Error 2

I also tried to install curl library non-static and everything went successfully but i want to have everything linked as one libary so it's not a good solution

My CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(testEnv)

# remove names of functions and optimize
set(CMAKE_CXX_FLAGS "-nolibc -s -O3 -Os -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -fuse-ld=lld")

set(CMAKE_CXX_STANDARD 17)

find_package(CURL CONFIG REQUIRED)


add_library(testEnv SHARED main.cpp)


target_link_libraries(testEnv CURL::libcurl)

#collect all needed libraries to run
target_link_libraries(testEnv -static)

Any ideas how to fix that problem with linking? Maybe there is any solutions which would allow to exclude those problematic libs?


Solution

mingw32-make

looks like you are using mingw. Consider using the correct vcpkg triplet, e.g. x64-mingw-static.cmake.

x64-windows-static will use an installed VS toolchain.

Be aware that you also need to set -DVCPKG_TARGET_TRIPLET=x64-mingw-static and -DVCPKG_HOST_TRIPLET=x64-mingw-static in your cmake call. Also make sure cmake does clean configure.



Answered By - Alexander Neumann
Answer Checked By - Marilyn (WPSolving Volunteer)