Error cross-compiling cpp-netlib for Raspbian - cmake

I've successfully compiled boost using the cross compiler (used the instructions from Installing Raspberry Pi Cross-Compiler) and it worked just fine.
I moved the lib and the include into the rootfs so that cmake finds it... and when I run cmake, I get
gervasio#ubuntu:~/cpp-netlib-0.10.1$ cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.55.0
-- Found the following Boost libraries:
-- unit_test_framework
-- system
-- regex
-- date_time
-- thread
-- filesystem
-- program_options
-- chrono
-- Found OpenSSL: /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so;/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so (found version "1..1")
-- Looking for include files CMAKE_HAVE_PTHREAD_H
-- Looking for include files CMAKE_HAVE_PTHREAD_H - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/gervasio/cpp-netlib-0.10.1
which is awesome... now, when I run make, it ends with
gervasio#ubuntu:~/cpp-netlib-0.10.1$ make
...
[ 15%] Building CXX object libs/network/test/CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o
cd /home/gervasio/cpp-netlib-0.10.1/libs/network/test && /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ -DBOOST_NETWORK_ENABLE_HTTPS -Wall -I/home/gervasio/raspberrypi/rootfs/usr/include -I/home/gervasio/cpp-netlib-0.10.1 -Wall -o CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o -c /home/gervasio/cpp-netlib-0.10.1/libs/network/test/message_test.cpp
Linking CXX executable ../../../tests/cpp-netlib-message_test
cd /home/gervasio/cpp-netlib-0.10.1/libs/network/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/cpp-netlib-message_test.dir/link.txt --verbose=1
/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ -Wall CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o -o ../../../tests/cpp-netlib-message_test -rdynamic /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_unit_test_framework.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_system.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_regex.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_date_time.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_thread.a -lpthread /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_filesystem.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_program_options.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_chrono.a -lpthread ../src/libcppnetlib-uri.a /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so -lrt -Wl,-rpath,/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf
/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: warning: libz.so.1, needed by /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so, not found (try using -rpath or -rpath-link)
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `deflateInit_'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `deflate'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `deflateEnd'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `inflate'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `inflateInit_'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `inflateEnd'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `zError'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/cpp-netlib-message_test] Error 1
make[2]: Leaving directory `/home/gervasio/cpp-netlib-0.10.1'
make[1]: *** [libs/network/test/CMakeFiles/cpp-netlib-message_test.dir/all] Error 2
make[1]: Leaving directory `/home/gervasio/cpp-netlib-0.10.1'
make: *** [all] Error 2
but... inside ~/raspberrypi/rootfs/lib/arm-linux-gnueabihf there's a libz.so.1
gervasio#ubuntu:~/raspberrypi/rootfs/lib/arm-linux-gnueabihf$ ls -lah libz.so*
lrwxrwxrwx 1 gervasio gervasio 13 Jun 24 2012 libz.so.1 -> libz.so.1.2.7
-rw-r--r-- 1 gervasio gervasio 86K Jun 24 2012 libz.so.1.2.7
I know it's failing just on the test, and that I can use the libraries... but I'd really like to have a good environment to cross compile whatever I need.
Thanks for your help :)
edit: just ran ldd libssl.so on the raspberry and got
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6ec6000)
libcrypto.so.1.0.0 => /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.0.0 (0xb6d57000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6d4c000)
libz.so.1 => /lib/arm-linux-gnueabihf/libz.so.1 (0xb6d2e000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6bff000)
/lib/ld-linux-armhf.so.3 (0xb6f24000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6bd7000)
edit 2: If I run cmake with -DCMAKE_SKIP_BUILD_RPATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE -DCMAKE_INSTALL_RPATH=/home/gervasio/raspberrypi/rootfs/lib/arm-linux-gnueabihf -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE I get this output
/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ -Wall CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o -o ../../../tests/cpp-netlib-message_test -rdynamic /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_unit_test_framework.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_system.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_regex.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_date_time.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_thread.a -lpthread /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_filesystem.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_program_options.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_chrono.a -lpthread ../src/libcppnetlib-uri.a /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so -lrt -Wl,-rpath,/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf
/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: warning: libz.so.1, needed by /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so, not found (try using -rpath or -rpath-link)
where it says -rpath,/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf that doesn't seem ok, right?

Thanks to #ruslo and that link he posted, I figured it out... this is the way to tell cmake to use rpath
cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake -DCMAKE_SKIP_BUILD_RPATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE -DCMAKE_INSTALL_RPATH=/home/gervasio/raspberrypi/rootfs/lib/arm-linux-gnueabihf -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE .

Related

cmake cross-compilation toolchain confusion

TL;DR: Why moving stuff around from the CMakeLists.txt to a dedicated toolchain file plays a role for find_package?
Trying to cross-compile with cmake and compile/link against pthread, I have the following dummy source file and CMakeLists.txt which work as expected together:
main.cc
#include <iostream>
#include <bits/c++config.h> // needed in the real world
int main()
{
std::cout << "Hello World !\n";
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(test VERSION 0.0.1)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabihf)
add_compile_options(-mtune=cortex-a9)
add_compile_definitions(_ARM_GCC_)
# Looking for cross compiler includes; maybe looking for rootfs-like stuff would be better
file(GLOB cross_includes LIST_DIRECTORIES true "/usr/arm-linux-gnueabihf/include/c++/*/arm-linux-gnueabihf/")
include_directories(SYSTEM ${cross_includes})
include_directories(SYSTEM /usr/arm-linux-gnueabihf/include)
find_package(Threads REQUIRED) # Not strictly necessary in this example but needed in the real world
add_executable(test main.cc)
Test:
$> rm -rf build/ && cmake -B build/ && make VERBOSE=1 -C build/
-- The C compiler identification is Clang 11.0.1
-- The CXX compiler identification is Clang 11.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jp/sandbox/so/cmake/build
make: Entering directory '/home/jp/sandbox/so/cmake/build'
/usr/bin/cmake -S/home/jp/sandbox/so/cmake -B/home/jp/sandbox/so/cmake/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/jp/sandbox/so/cmake/build/CMakeFiles /home/jp/sandbox/so/cmake/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/jp/sandbox/so/cmake/build'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
make[2]: Entering directory '/home/jp/sandbox/so/cmake/build'
cd /home/jp/sandbox/so/cmake/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jp/sandbox/so/cmake /home/jp/sandbox/so/cmake /home/jp/sandbox/so/cmake/build /home/jp/sandbox/so/cmake/build /home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/DependInfo.cmake --color=
Dependee "/home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/DependInfo.cmake" is newer than depender "/home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/depend.internal".
Dependee "/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/depend.internal".
Scanning dependencies of target test
make[2]: Leaving directory '/home/jp/sandbox/so/cmake/build'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
make[2]: Entering directory '/home/jp/sandbox/so/cmake/build'
[ 50%] Building CXX object CMakeFiles/test.dir/main.cc.o
/usr/bin/clang++ --target=arm-linux-gnueabihf -D_ARM_GCC_ -isystem /usr/arm-linux-gnueabihf/include/c++/10/arm-linux-gnueabihf -isystem /usr/arm-linux-gnueabihf/include -g -mtune=cortex-a9 -std=c++17 -o CMakeFiles/test.dir/main.cc.o -c /home/jp/sandbox/so/cmake/main.cc
[100%] Linking CXX executable test
/usr/bin/cmake -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/clang++ --target=arm-linux-gnueabihf -g -rdynamic CMakeFiles/test.dir/main.cc.o -o test
make[2]: Leaving directory '/home/jp/sandbox/so/cmake/build'
[100%] Built target test
make[1]: Leaving directory '/home/jp/sandbox/so/cmake/build'
/usr/bin/cmake -E cmake_progress_start /home/jp/sandbox/so/cmake/build/CMakeFiles 0
make: Leaving directory '/home/jp/sandbox/so/cmake/build'
So far, everything works fine.
Now, the tricky part: I'd like to put the cross-compilation specific stuff in a toolchain.cmake file
toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabihf)
add_compile_options(-mtune=cortex-a9)
add_compile_definitions(_ARM_GCC_)
# Looking for cross compiler includes; maybe looking for rootfs-like stuff would be better
file(GLOB cross_includes LIST_DIRECTORIES true "/usr/arm-linux-gnueabihf/include/c++/*/arm-linux-gnueabihf/")
include_directories(SYSTEM ${cross_includes})
include_directories(SYSTEM /usr/arm-linux-gnueabihf/include)
new CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(test VERSION 0.0.1)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Threads REQUIRED) # Not strictly necessary in this example but needed in the real world
add_executable(test main.cc)
Test:
$> rm -rf build/ && cmake -B build/ -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake && make VERBOSE=1 -C build/
-- The C compiler identification is Clang 11.0.1
-- The CXX compiler identification is Clang 11.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - not found
CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.18/Modules/FindThreads.cmake:234 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:11 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeOutput.log".
See also "/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeError.log".
Actually, cmake finds pthread.h but clang cannot compile it (wrong floating point abi used; stubs-hard.h should be included)
build/CMakeFiles/CMakeError.log
Determining if the include file pthread.h exists failed with the following output:
Change Dir: /home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/gmake cmTC_76e89/fast && /usr/bin/gmake -f CMakeFiles/cmTC_76e89.dir/build.make CMakeFiles/cmTC_76e89.dir/build
gmake[1]: Entering directory '/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_76e89.dir/CheckIncludeFile.c.o
/usr/bin/clang -D_ARM_GCC_ -isystem /usr/arm-linux-gnueabihf/include/c++/10/arm-linux-gnueabihf -isystem /usr/arm-linux-gnueabihf/include/gnu -isystem /usr/arm-linux-gnueabihf/include -mtune=cortex-a9 -o CMakeFiles/cmTC_76e89.dir/CheckIncludeFile.c.o -c /home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp/CheckIncludeFile.c
In file included from /home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:
In file included from /usr/arm-linux-gnueabihf/include/pthread.h:21:
In file included from /usr/arm-linux-gnueabihf/include/features.h:485:
/usr/arm-linux-gnueabihf/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-soft.h' file not found
# include <gnu/stubs-soft.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
gmake[1]: *** [CMakeFiles/cmTC_76e89.dir/build.make:85: CMakeFiles/cmTC_76e89.dir/CheckIncludeFile.c.o] Error 1
gmake[1]: Leaving directory '/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:140: cmTC_76e89/fast] Error 2
Some more Info:
I made sure the toolchain.cmake is considered (triggered a parse error to check)
$> cat toolchain.cmake CMakeLists.txt
produces the same output as the "original" CMakeLists.txt
pthread.h can be found on my System at the following locations:
$> find /usr/ -name pthread.h
/usr/arm-linux-gnueabi/include/pthread.h
/usr/arm-linux-gnueabihf/include/pthread.h
/usr/include/newlib/pthread.h /usr/include/pthread.h
As #Tsyvarev pointed out, the CMakeError.log contained useful information (the question was edited with its content).
The issue:
cmake finds pthread.h but clang cannot compile it
...
/usr/arm-linux-gnueabihf/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-soft.h' file not found
...
The clang invocation is interesting because of "/usr/bin/clang" (expected clang++) and no -target flag used
The solution:
Tell cmake to also use a specific -target flag for C cross-compilers supoorting it:
Add the following in target.cmake
set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabihf)
(Same target as CMAKE_CXX_COMPILER_TARGET)

Trouble with simple CMAKE tutorial

I just followed the simple CMake tutorial on youtube
https://www.youtube.com/watch?v=V1YP7eJHDJE
As you can see through the youtube,
folder directory is
CMAKE-GOOD
-build
-CMakeLists.txt
-main.cpp
this is CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(MyProject VERSION 1.0.0)
add_executable(cmake-good main.cpp)
this is main.cpp
#include <iostream>
int main()
{
std::cout << "hello, world! \n";
}
it is the only source code that I wrote.
and from this part, this will be covered my errors that I encountered
edit) I also did the cmake .. in the build directory
the result was shown in below
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bmssa/Desktop/CMake_tutorial/CMAKE-GOOD/build
when I type cmake --build . in ~Desktop/CMake_tutorial_CMAKE_GOOD/build, it shows an Error with
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD/build$ cmake --build .
[ 50%] Linking CXX executable cmake-good
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
CMakeFiles/cmake-good.dir/build.make:96: recipe for target 'cmake-good' failed
make[2]: *** [cmake-good] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/cmake-good.dir/all' failed
make[1]: *** [CMakeFiles/cmake-good.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
as I heard cmake --build . is similar to make,
so I tried make and it shows an error like this
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD/build$ make
[ 50%] Linking CXX executable cmake-good
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
CMakeFiles/cmake-good.dir/build.make:96: recipe for target 'cmake-good' failed
make[2]: *** [cmake-good] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/cmake-good.dir/all' failed
make[1]: *** [CMakeFiles/cmake-good.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
when I type cmake --version,
cmake version 3.20.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Can you please help me how to fix it?
I couldn't do anything because I can't even solve this one simple error in the very easy tutorial.
Please HELP ME PLEASE
Thank you
ps.
Because I don't even know what is an error in CMake, could you tell me what should I type in google to solve this?
recipe for taget?
recipe for target 'all' failed?
I don't know what should I type in google....
edit2) I also did the cmake -S . -B build/foobar and cmake --build build/foobar and this also shows the similar Error like this
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD$ cmake -S . -B build/foobar
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bmssa/Desktop/CMake_tutorial/CMAKE-GOOD/build/foobar
(base) bmssa#bmssa:~/Desktop/CMake_tutorial/CMAKE-GOOD$ cmake --build build/foobar
[ 50%] Building CXX object CMakeFiles/cmake-good.dir/main.cpp.o
[100%] Linking CXX executable cmake-good
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
CMakeFiles/cmake-good.dir/build.make:96: recipe for target 'cmake-good' failed
make[2]: *** [cmake-good] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/cmake-good.dir/all' failed
make[1]: *** [CMakeFiles/cmake-good.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
Here is my guess to your problem. CMake is unable to find a working toolchain (Compiler, linker, etc.)
Try helping it out by specifying the environment variables CC and CXX.
https://cmake.org/cmake/help/latest/envvar/CXX.html
https://cmake.org/cmake/help/latest/envvar/CC.html
export CC = /foobar/...../gcc
export CXX = /foobar/...../g++
For future reference here is how CMake finds compilers (according to a CMake dev)
CMAKE_TOOLCHAIN_FILE (if provided)
CMAKE_LANG_COMPILER (if provided)
The environment variables CC or CXX (if provided)
Then it searches the path environment variable to see if it can find anything.
I guess in your situation none of the above worked. So setting CC and CXX fixed it.

why 'target_link_libraries' command is not working? (cplex)

I tried to compile an project with cmake command(all implementation is written by other people. my job is just compile and run.)
error messages after cmake
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: bad revision 'HEAD'
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.10")
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- CPLEX Library: /opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic/libcplex.a
-- ILOCPLEX Library: /opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic/libilocplex.a
-- CONCERT Library: /opt/ibm/ILOG/CPLEX_Studio1210/concert/lib/x86-64_linux/static_pic/libconcert.a
-- CPLEX Bin Dir: /opt/ibm/ILOG/CPLEX_Studio1210/cplex/bin/x86-64_linux
-- Found CPLEX: /opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic/libcplex.a
-- Configuring done
CMake Error at cpxutils/CMakeLists.txt:25 (add_executable):
Target "cpx_solver" links to target "Cplex::Cplex" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at cpxutils/CMakeLists.txt:13 (add_library):
Target "cpxutils" links to target "Cplex::Cplex" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at feaspump/CMakeLists.txt:17 (add_executable):
Target "fp2" links to target "Cplex::Cplex" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
CMake Error at feaspump/CMakeLists.txt:5 (add_library):
Target "fp" links to target "Cplex::Cplex" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
and this is cpxutils/CMakeLists.txt file.
cmake_minimum_required(VERSION 3.6)
# Find CPLEX library
find_package(CPLEX)
# Export CPLEX_FOUND for CMakeLists.txt files in other subdirectories
set(CPLEX_FOUND ${CPLEX_FOUND} PARENT_SCOPE)
if (CPLEX_FOUND)
# Define libcpxutils
add_library(cpxutils STATIC cpxutils.cpp cpxmacro.cpp model.cpp gomory.cpp cpxapp.cpp)
target_include_directories(cpxutils PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(cpxutils PUBLIC utils Cplex::Cplex)
add_library(Cpxutils::Lib ALIAS cpxutils)
# Define cpx_solver executable
add_executable(cpx_solver EXCLUDE_FROM_ALL cpx_solver.cpp)
target_include_directories(cpx_solver PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(cpx_solver PUBLIC utils Cpxutils::Lib)
else()
message(WARNING "Disabling CPXUTILS subproject")
endif()
i don't know why cannot find target despite CPLEX package is found.
i'm using WSL1 (Ubuntu) environment.
↑ problem solved. thanks for #Tsyvarev.
=== additional problem ===
Even though cmake commad works without any error, I cant find execution file. So I checked 'CMakeError.log' file then, there are some error.
This is CMakeError.log file.
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /mnt/c/Users/aero5010/Desktop/CBC+FP/CBC+FP/fp2/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_92254/fast && /usr/bin/make -f CMakeFiles/cmTC_92254.dir/build.make CMakeFiles/cmTC_92254.dir/build
make[1]: Entering directory '/mnt/c/Users/aero5010/Desktop/CBC+FP/CBC+FP/fp2/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_92254.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_92254.dir/src.c.o -c /mnt/c/Users/aero5010/Desktop/CBC+FP/CBC+FP/fp2/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_92254
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_92254.dir/link.txt --verbose=1
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD CMakeFiles/cmTC_92254.dir/src.c.o -o cmTC_92254
/usr/bin/ld: CMakeFiles/cmTC_92254.dir/src.c.o: in function `main':
src.c:(.text+0x46): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text+0x52): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text+0x63): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_92254.dir/build.make:87: cmTC_92254] Error 1
make[1]: Leaving directory '/mnt/c/Users/aero5010/Desktop/CBC+FP/CBC+FP/fp2/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_92254/fast] Error 2
Source file was:
#include <pthread.h>
void* test_func(void* data)
{
return data;
}
int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);
return 0;
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /mnt/c/Users/aero5010/Desktop/CBC+FP/CBC+FP/fp2/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_8ae2b/fast && /usr/bin/make -f CMakeFiles/cmTC_8ae2b.dir/build.make CMakeFiles/cmTC_8ae2b.dir/build
make[1]: Entering directory '/mnt/c/Users/aero5010/Desktop/CBC+FP/CBC+FP/fp2/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8ae2b.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_8ae2b.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_8ae2b
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8ae2b.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_8ae2b.dir/CheckFunctionExists.c.o -o cmTC_8ae2b -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_8ae2b.dir/build.make:87: cmTC_8ae2b] Error 1
make[1]: Leaving directory '/mnt/c/Users/aero5010/Desktop/CBC+FP/CBC+FP/fp2/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_8ae2b/fast] Error 2
I think this is why i cant find execution file. But I dont know why this error occured despite pthread library is installed well...
** thank you for every advice about Stackoverflow Manners.

CMake 3.0+Fortran+CUDA requires -fPIC even when building executables

This is a CMake question. I cannot compile Fortran executables with CUDA support when using the Intel Fortran compiler, unless I include the -fPIC flag. The problem is that -fPIC shouldn't be necessary unless I'm building a library.
The following is minimal example:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(cuda LANGUAGES Fortran CXX)
find_package(CUDA)
cuda_add_executable(main main.f90)
and
# main.f90
end
When I try to build and run,
cmake -D CMAKE_Fortran_COMPILER=ifort .. && make VERBOSE=1
I get the following:
-- The Fortran compiler identification is Intel 18.0.0.20170811
-- The CXX compiler identification is GNU 7.3.0
-- Check for working Fortran compiler: /opt/intel/compilers_and_libraries_2018.0.128/linux/bin/intel64/ifort
-- Check for working Fortran compiler: /opt/intel/compilers_and_libraries_2018.0.128/linux/bin/intel64/ifort -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /opt/intel/compilers_and_libraries_2018.0.128/linux/bin/intel64/ifort supports Fortran 90
-- Checking whether /opt/intel/compilers_and_libraries_2018.0.128/linux/bin/intel64/ifort supports Fortran 90 -- yes
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /opt/cuda (found version "9.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/raul/tmp/cuda/build
/usr/bin/cmake -H/home/raul/tmp/cuda -B/home/raul/tmp/cuda/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/raul/tmp/cuda/build/CMakeFiles /home/raul/tmp/cuda/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/raul/tmp/cuda/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
make[2]: Entering directory '/home/raul/tmp/cuda/build'
cd /home/raul/tmp/cuda/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/raul/tmp/cuda /home/raul/tmp/cuda /home/raul/tmp/cuda/build /home/raul/tmp/cuda/build /home/raul/tmp/cuda/build/CMakeFiles/main.dir/DependInfo.cmake --color=
Dependee "/home/raul/tmp/cuda/build/CMakeFiles/main.dir/DependInfo.cmake" is newer than depender "/home/raul/tmp/cuda/build/CMakeFiles/main.dir/depend.internal".
Dependee "/home/raul/tmp/cuda/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/raul/tmp/cuda/build/CMakeFiles/main.dir/depend.internal".
Scanning dependencies of target main
make[2]: Leaving directory '/home/raul/tmp/cuda/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/requires
make[2]: Entering directory '/home/raul/tmp/cuda/build'
make[2]: Nothing to be done for 'CMakeFiles/main.dir/requires'.
make[2]: Leaving directory '/home/raul/tmp/cuda/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
make[2]: Entering directory '/home/raul/tmp/cuda/build'
[ 50%] Building Fortran object CMakeFiles/main.dir/main.f90.o
/opt/intel/compilers_and_libraries_2018.0.128/linux/bin/intel64/ifort -I/opt/cuda/include -c /home/raul/tmp/cuda/main.f90 -o CMakeFiles/main.dir/main.f90.o
[100%] Linking CXX executable main
/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/main.dir/main.f90.o -o main /opt/cuda/lib64/libcudart_static.a -lpthread -ldl -lrt -lifport -lifcoremt -limf -lsvml -lipgo -lirc -lpthread -lsvml -lirc_s -ldl
/usr/bin/ld: CMakeFiles/main.dir/main.f90.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../lib/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/usr/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:97: main] Error 1
make[2]: Leaving directory '/home/raul/tmp/cuda/build'
make[1]: *** [CMakeFiles/Makefile2:69: CMakeFiles/main.dir/all] Error 2
make[1]: Leaving directory '/home/raul/tmp/cuda/build'
make: *** [Makefile:84: all] Error 2
I do not get the build error if I use the newer CUDA features of CMake, e.g.
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(cuda LANGUAGES Fortran CUDA)
add_executable(main main.f90)
However, our current policy is to support CMake 3.0 and thus I cannot the simpler version. Also, I do not get any error if instead of ifort I use gfortran. I'm currently looking into FindCUDA.cmake that ships with CMake, but I haven't found a solution yet. Any thoughts?
I found a solution that works for now, but it's not trivial at all. First, one should use icpc with ifort (not a requirement for CMake >=3.8). It turns out that out of the many libraries that icpc links against under the hood (you won't see them without running make VERBOSE=1), one of them (but not others) should be linked against statically. Thus, by specifying
target_link_libraries(main ifcoremt.a)
in CMakeLists.txt seems to fix the problem, at least for me.

cmake unable to find libstdc++

(Using elementaryOS/Ubuntu)
I'm cross-compiling x265 and I encouraged annoying problem. For some reason cmake doesn't want to accept -static-libstdc++, because ld is apparently unable to find it. Cmake is built from Source Code, working pretty well without -static-libstdc++, if I then copy libstdc++-6.dll from mingw-w64 libs to folder with x265.exe, it works well, but I want it to build with it. mingw was built with this script and contains these libraries, but I don't know where is ld looking for them.
Here is output of cmake attempt:
-- cmake version 3.5.0-rc1
-- The C compiler identification is GNU 5.2.0
-- The CXX compiler identification is GNU 5.2.0
-- Check for working C compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++ -- broken
CMake Error at /usr/local/share/cmake-3.5/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler
"/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++" is not
able to compile a simple test program.
It fails with the following output:
Change Dir: /home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_e7611/fast"
/usr/bin/make -f CMakeFiles/cmTC_e7611.dir/build.make
CMakeFiles/cmTC_e7611.dir/build
make[1]: Entering directory
`/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_e7611.dir/testCXXCompiler.cxx.obj
/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++
-static-libgcc -static-libstdc++ -o
CMakeFiles/cmTC_e7611.dir/testCXXCompiler.cxx.obj -c
/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_e7611.exe
/usr/local/bin/cmake -E cmake_link_script
CMakeFiles/cmTC_e7611.dir/link.txt --verbose=1
/usr/local/bin/cmake -E remove -f CMakeFiles/cmTC_e7611.dir/objects.a
/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-ar cr
CMakeFiles/cmTC_e7611.dir/objects.a #CMakeFiles/cmTC_e7611.dir/objects1.rsp
/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++
-static-libgcc -static-libstdc++ -Wl,--whole-archive
CMakeFiles/cmTC_e7611.dir/objects.a -Wl,--no-whole-archive -o
cmTC_e7611.exe -Wl,--out-implib,libcmTC_e7611.dll.a
-Wl,--major-image-version,0,--minor-image-version,0
#CMakeFiles/cmTC_e7611.dir/linklibs.rsp
/home/myname/mingw-w64/mingw-w64-x86_64/lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/bin/ld:
cannot find -lstdc++
collect2: error: ld returned 1 exit status
make[1]: *** [cmTC_e7611.exe] Error 1
make[1]: Leaving directory
`/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp'
make: *** [cmTC_e7611/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:19 (project)
-- Configuring incomplete, errors occurred!
See also "/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeOutput.log".
See also "/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found. Stop.
Cmake is run like code below.
cmake -DCMAKE_C_COMPILER='/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-gcc' -DCMAKE_CXX_COMPILER='/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++' -DCMAKE_RC_COMPILER='/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-windres' -DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++" -DCMAKE_C_FLAGS="-static-libgcc -static-libstdc++" -DCMAKE_TOOLCHAIN_FILE='/home/myname/x265/build/linux/build.cmake' ../../../source -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DMAIN12=ON
make ${MAKEFLAGS}
build.cmake file is not much important here, but it contains:
SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_ASM_YASM_COMPILER yasm)
Any ideas how to make -static-libstdc++ work? I tried linking it in many folders, but I couldn't find out where is ld looking for it.
I managed to solve this. Source of my confusion was the fact that you can use -static-libgcc, so I thought even -static-libstdc++ should work. The problem was that there indeed were libraries, but not the .a files for libstdc++. These can be disabled using this parameter when using the script. Then both -static-lib options work well.
bash ./mingw-w64-build-3.6.7 --disable-shared