I try to build clFFT library (for doing FFT with OpenCL) and examples contained into clFFT git.
First, into /opt/, I did :
git clone https://github.com/clMathLibraries/clFFT.git
After, always into /opt/ directory, I did : $ mkdir build && cd build/
from here, I called cmake like this :
cmake -DOpenCL_INCLUDE_DIR=/opt/AMDAPPSDK-3.0/include -DOpenCL_LIBRARY=/opt/AMDAPPSDK-3.0/lib/x86_64 ../clFFT/src/
Indeed, into /opt/ directory, I have installed AMDAPPSDK-3.0from the AMD-APP-SDKInstaller-v3.0.130.136-GA-linux64.tar.bz2archive.
Everything seems to be valid for the compilation of clFFT but it fails :
4.1) First, at the end of cmakecommand above, I get :
cmake -DOpenCL_INCLUDE_DIR=/opt/AMDAPPSDK-3.0/include -DOpenCL_LIBRARY=/opt/AMDAPPSDK-3.0/lib/x86_64 ../clFFT/src/
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.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
-- UNICODE feature disabled on linux
-- 64bit build - FIND_LIBRARY_USE_LIB64_PATHS TRUE
-- Could NOT find Boost
CMake Warning at CMakeLists.txt:146 (message):
Try setting Boost_DEBUG and Boost_DETAILED_FAILURE_MSG for more information
-- Looking for CL_VERSION_2_2
-- Looking for CL_VERSION_2_2 - not found
-- Looking for CL_VERSION_2_1
-- Looking for CL_VERSION_2_1 - not found
-- Looking for CL_VERSION_2_0
-- Looking for CL_VERSION_2_0 - found
-- Found OpenCL: /opt/AMDAPPSDK-3.0/lib/x86_64 (found version "2.0")
-- Found FFTW: /usr/lib/x86_64-linux-gnu/libfftw3f.so;/usr/lib/x86_64-linux-gnu/libfftw3.so
-- Detected GNU fortran compiler.
-- CMAKE_CXX_COMPILER flags: -m64 -pthread
-- CMAKE_CXX_COMPILER debug flags: -g
-- CMAKE_CXX_COMPILER release flags: -O3 -DNDEBUG
-- CMAKE_CXX_COMPILER relwithdebinfo flags: -O2 -g -DNDEBUG
-- CMAKE_EXE_LINKER link flags:
FFT clients will NOT be built
GoogleTest unit tests will NOT be built
FFT callback client will NOT be built
-- Configuring done
WARNING: Target "clFFT" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "clFFT" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "StatTimer" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "StatTimer" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "example_examples_fft2d" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "example_examples_fft3d" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "example_examples_fft1d" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /opt/build
more precisely, I am talking about :
-- Configuring done
WARNING: Target "clFFT" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "clFFT" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "StatTimer" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "StatTimer" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "example_examples_fft2d" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "example_examples_fft3d" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "example_examples_fft1d" requests linking to directory "/opt/AMDAPPSDK-3.0/lib/x86_64". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /opt/build
4.2) After launching makeinto /opt/build/ directory, I get the following warnings :
$ make
Scanning dependencies of target clFFT
[ 3%] Building CXX object library/CMakeFiles/clFFT.dir/transform.cpp.o
In file included from /opt/clFFT/src/library/repo.h:26,
from /opt/clFFT/src/library/transform.cpp:23:
/opt/clFFT/src/library/../statTimer/statisticalTimer.GPU.h:132:42: warning: ignoring attributes on template argument âcl_uintâ {aka âunsigned intâ} [-Wignored-attributes]
typedef std::pair< std::string, cl_uint > idPair;
^
[ 7%] Building CXX object library/CMakeFiles/clFFT.dir/accessors.cpp.o
In file included from /opt/clFFT/src/library/repo.h:26,
from /opt/clFFT/src/library/accessors.cpp:23:
/opt/clFFT/src/library/../statTimer/statisticalTimer.GPU.h:132:42: warning: ignoring attributes on template argument âcl_uintâ {aka âunsigned intâ} [-Wignored-attributes]
typedef std::pair< std::string, cl_uint > idPair;
^
[ 11%] Building CXX object library/CMakeFiles/clFFT.dir/plan.cpp.o
In file included from /opt/clFFT/src/library/repo.h:26,
from /opt/clFFT/src/library/plan.cpp:25:
/opt/clFFT/src/library/../statTimer/statisticalTimer.GPU.h:132:42: warning: ignoring attributes on template argument âcl_uintâ {aka âunsigned intâ} [-Wignored-attributes]
typedef std::pair< std::string, cl_uint > idPair;
^
[ 15%] Building CXX object library/CMakeFiles/clFFT.dir/repo.cpp.o
In file included from /opt/clFFT/src/library/repo.h:26,
from /opt/clFFT/src/library/repo.cpp:22:
...
and finally, I get the following ending errors :
[ 80%] Building C object examples/CMakeFiles/example_examples_fft2d.dir/fft2d.c.o
/opt/clFFT/src/examples/fft2d.c: In function âmainâ:
/opt/clFFT/src/examples/fft2d.c:63:5: warning: âclCreateCommandQueueâ is deprecated [-Wdeprecated-declarations]
queue = clCreateCommandQueue( ctx, device, 0, &err );
^~~~~
In file included from /opt/clFFT/src/include/clFFT.h:33,
from /opt/clFFT/src/examples/fft2d.c:21:
/opt/AMDAPPSDK-3.0/include/CL/cl.h:1359:1: note: declared here
clCreateCommandQueue(cl_context /* context */,
^~~~~~~~~~~~~~~~~~~~
[ 84%] Linking C executable examples/fft2d
/usr/bin/ld: CMakeFiles/example_examples_fft2d.dir/fft2d.c.o: in function `main':
fft2d.c:(.text.startup+0x76): undefined reference to `clGetPlatformIDs'
/usr/bin/ld: fft2d.c:(.text.startup+0x9d): undefined reference to `clGetPlatformInfo'
/usr/bin/ld: fft2d.c:(.text.startup+0xd1): undefined reference to `clGetDeviceIDs'
/usr/bin/ld: fft2d.c:(.text.startup+0xf6): undefined reference to `clGetDeviceInfo'
/usr/bin/ld: fft2d.c:(.text.startup+0x13c): undefined reference to `clCreateContext'
/usr/bin/ld: fft2d.c:(.text.startup+0x152): undefined reference to `clCreateCommandQueue'
/usr/bin/ld: fft2d.c:(.text.startup+0x215): undefined reference to `clCreateBuffer'
/usr/bin/ld: fft2d.c:(.text.startup+0x241): undefined reference to `clEnqueueWriteBuffer'
/usr/bin/ld: fft2d.c:(.text.startup+0x307): undefined reference to `clFinish'
/usr/bin/ld: fft2d.c:(.text.startup+0x334): undefined reference to `clEnqueueReadBuffer'
/usr/bin/ld: fft2d.c:(.text.startup+0x3a7): undefined reference to `clReleaseMemObject'
/usr/bin/ld: fft2d.c:(.text.startup+0x3cc): undefined reference to `clReleaseCommandQueue'
/usr/bin/ld: fft2d.c:(.text.startup+0x3d5): undefined reference to `clReleaseContext'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clBuildProgram'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clEnqueueNDRangeKernel'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clSetKernelArg'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clGetCommandQueueInfo'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clReleaseEvent'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clGetProgramBuildInfo'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clGetContextInfo'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clCreateProgramWithBinary'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clRetainContext'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clReleaseProgram'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clGetProgramInfo'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clCreateKernel'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clCreateProgramWithSource'
/usr/bin/ld: ../library/libclFFT.so.2.14.0: undefined reference to `clReleaseKernel'
collect2: error: ld returned 1 exit status
make[2]: *** [examples/CMakeFiles/example_examples_fft2d.dir/build.make:85: examples/examples/fft2d] Error 1
make[1]: *** [CMakeFiles/Makefile2:223: examples/CMakeFiles/example_examples_fft2d.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
I don't understand where these errors could come from, it seems that the library libclFFT.so.2.14.0 I have built doesn't contain the references to OpenCL basic functions (like clGetPlatformIDs or clCreateCommandQueue...).
Moreover, I don't know why the path of undefined reference is to the upper level, i.e /usr/bin/ld: ../library/libclFFT.so.2.14.0, because the library is built into /opt/build/library directory.
I would like to be able to compile fine the libclFFT.so that takes into account the OpenCL headers indicated by the path OpenCL_INCLUDE_DIR and library by OpenCL_LIBRARY.
I have to solve this issue of path taken by cmake, i.e : ../library/libclFFT.so.2.14.0and include into the building of this library all the OpenCL functions from AMDAPPSDK.
The cmake setup on your machine should have an OpenCL finder, which is called by the command find_package(OpenCL) when the cmake executes the CMakeLists.txt file from the clFFT distribution (this command can be used also in your own CMakeLists.txt files). This finder is simply a file, named FindOpenCL.cmake, which must be a part of the cmake configuration. Make sure you have this file:
find /usr -name FindOpenCL.cmake
If you have this finder you won't need to set variables OpenCL_INCLUDE_DIR and OpenCL_LIBRARY in the cmake call - the finder will find all the needed OpenCL paths. If you have this finder but it doesn't work correctly - then it'll be a question for its developers. If you don't have this finder then it'll be a problem in the cmake installation and/or setup. This finder is described here.
According to our conversation in comments, you tried to use the AMD APP SDK v3.0 package on MacOS - this couldn't work because AMD supported only Windows and Linux operating systems. It's understandable because Apple has long history of its own OpenCL support - please see here.
Related
I'm interested in statically linking PROJ to a library created with pybind11.
but, I get error by cmake.
Why am I getting this error and how can I fix it?
My CMakeLists.txt is this.
cmake_minimum_required(VERSION 3.4)
project(myearth LANGUAGES CXX)
add_subdirectory(pybind11)
pybind11_add_module(myearth MyEarth.cpp)
include_directories(${CMAKE_SOURCE_DIR}/PROJ/include)
add_library(proj4 STATIC IMPORTED)
set_target_properties(proj4 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/PROJ/lib/libproj.a)
target_link_libraries(myearth PRIVATE proj4)
CMake Error.
I think fPIC option is for shared library. so, libproj.a is not necessary this option because this is static library.
(venv) ~/Projects/LinkLibTest/MySample/build$ make
[ 50%] Building CXX object CMakeFiles/myearth.dir/MyEarth.cpp.o
[100%] Linking CXX shared module myearth.cpython-36m-x86_64-linux-gnu.so
/usr/bin/ld: ../PROJ/lib/libproj.a(proj_4D_api.o): relocation R_X86_64_PC32 against symbol `pj_errno' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/myearth.dir/build.make:98: myearth.cpython-36m-x86_64-linux-gnu.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/myearth.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
(venv) ~/Projects/LinkLibTest/MySample/build$
I created libproj.a by the following command.
$ ./configure --prefix=/output --disable-shared
$ sudo make
$ sudo make install
Linux Mint 20.3 64bit
CMake v3.22.2
PROJ v5.2.0 (https://proj.org/)
Python v3.6.8
Thank you.
Shared libraries must have position independent code, but your version of PROJ was built without it; you will have to rebuild PROJ with PIC.
$ ./configure --prefix=/output --with-pic
I have a program that compiles on my target machine (NVIDIA Jetson). Now I am trying to cross compile the same program on my laptop. I have a cross compiler and cloned the Jetson to use as a sysroot. I was following this guide from NVIDIA. My program compiles, but fails at a linking step. I'm linking against a library (protobuf) and the linker can't find the dependencies of the library. I have produced a minimal example that demonstrates this.
main.cpp:
#include <google/protobuf/util/json_util.h>
int main(int argc, char* argv[])
{
google::protobuf::util::JsonPrintOptions jsonOptions;
jsonOptions.always_print_enums_as_ints = true;
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(Test)
find_package(Protobuf REQUIRED)
add_executable(Test main.cpp)
target_include_directories(Test PRIVATE ${PROTOBUF_INCLUDE_DIRS})
target_link_libraries(Test PRIVATE ${PROTOBUF_LIBRARIES})
On my target computer CMake generates and builds this fine, but when cross compiling on my laptop CMake generates the makefiles, and the build step fails with the error:
[ 50%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
[100%] Linking CXX executable Test
/home/lhahn/Documents/CrossCompilation/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.3.1/../../../../aarch64-linux-gnu/bin/ld: warning: libz.so.1, needed by /home/lhahn/Documents/CrossCompilation/Images/jetson/usr/local/lib/libprotobuf.so, not found (try using -rpath or -rpath-link)
/home/lhahn/Documents/CrossCompilation/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.3.1/../../../../aarch64-linux-gnu/bin/ld: warning: libm.so.6, needed by /home/lhahn/Documents/CrossCompilation/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.3.1/../../../../aarch64-linux-gnu/lib/../lib64/libstdc++.so, not found (try using -rpath or -rpath-link)
/home/lhahn/Documents/CrossCompilation/Images/jetson/usr/local/lib/libprotobuf.so: undefined reference to `deflateInit2_'
/home/lhahn/Documents/CrossCompilation/Images/jetson/usr/local/lib/libprotobuf.so: undefined reference to `deflate'
/home/lhahn/Documents/CrossCompilation/Images/jetson/usr/local/lib/libprotobuf.so: undefined reference to `deflateEnd'
/home/lhahn/Documents/CrossCompilation/Images/jetson/usr/local/lib/libprotobuf.so: undefined reference to `inflate'
/home/lhahn/Documents/CrossCompilation/Images/jetson/usr/local/lib/libprotobuf.so: undefined reference to `inflateInit2_'
/home/lhahn/Documents/CrossCompilation/Images/jetson/usr/local/lib/libprotobuf.so: undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/Test.dir/build.make:98: Test] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/Test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
The required library (ZLIB) exists in my sysroot (/home/lhahn/Documents/CrossCompilation/Images/jetson/usr/lib/aarch64-linux-gnu/libz.so), but the linker can't find it.
My toolchain file is
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_SYSROOT /home/lhahn/Documents/CrossCompilation/Images/jetson)
set(CMAKE_C_COMPILER /home/lhahn/Documents/CrossCompilation/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /home/lhahn/Documents/CrossCompilation/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH /home/lhahn/Documents/CrossCompilation/Images/jetson)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
What do I need to tell CMake so that the linker can find these secondary dependencies?
I figured out my problem. When I cloned the image and mounted it on my laptop I broke all of the symlinks in the cloned image, such as libz.so which is why cmake couldn't find them. When I fixed the symlink cmake went on to complain about the next broken symlink in the same manner. I think there are too many symlinks to fix them manually, but at least now I know what went wrong.
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.
My CMakeList.txt has the following problematic section:
add_executable(esh_test tests/libtest.c esh.c tests/esh_test.cpp)
add_dependencies(esh_test esh)
target_link_libraries(esh_test
${CMAKE_SOURCE_DIR}/esh-grammar.o
${CMAKE_SOURCE_DIR}/libesh.a
l dl readline curses libgtest gtest_main)
Problematic because it won't link properly:
$> cmake ./; make
-- Configuring done
-- Generating done
-- Build files have been written to: src/
[ 0%] Built target lexpar
[ 0%] Built target libesh
[ 14%] Built target esh
[ 71%] Built target gtest
[ 78%] Linking CXX executable esh_test
CMakeFiles/esh_test.dir/esh_test.cpp.o: In function `testcase_test_test_Test::TestBody()':
esh_test.cpp:(.text+0xe): undefined reference to `mkredir()'
esh_test.cpp:(.text+0x1c): undefined reference to `esh_usage(char*)'
esh_test.cpp:(.text+0x28): undefined reference to `redir_restore_streams(redir*)'
esh_test.cpp:(.text+0x3a): undefined reference to `fd_grep_regex(int, char*)'
esh_test.cpp:(.text+0x107): undefined reference to `redir_cleanup(redir*)'
collect2: error: ld returned 1 exit status
The link.txt for this module is:
/usr/bin/c++ -std=c++11 CMakeFiles/esh_test.dir/esh_test.cpp.o CMakeFiles/esh_test.dir/libtest.c.o CMakeFiles/esh_test.dir/esh.c.o -o esh_test -rdynamic ../esh-grammar.o ../libesh.a -ll -ldl -lreadline -lcurses gtest/src/gtest-build/libgtest.a -lgtest_main -lpthread
Which seems like it would link in the missing functions, declared in libtest.h and defined in libtest.c.
This is my first CMake project, so I'm a little lost. What's going on here?
I'm trying to compile a program provided to me. I noticed in the Makefile it runs the command
g++ -o test [...] -lpthread
I noticed the pthread library file is in /lib/libpthread.so.0 , but when I try to make the target, it gives me this error:
/usr/bin/ld: cannot find -lpthread
collect2: ld returned 1 exit status
how do I fix this?
In order to use -lpthread, you need a libpthread.a library archive and this is for static linking. libpthread.so.0 is a shared object which means it is used for dynamic linking. See GCC Link Options