2

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.

  • 1
    Welcome to Stack Overflow! Here we prefer **text** to the *links* and *screenshots* which contains just text. Please, **paste** the error log to the question post as **text**, not as image. You may format this text as a *code*, with `Ctrl+K` or `{}` button. See also [ask]. – Tsyvarev Jul 03 '20 at 06:34
  • As for `Cplex::Cplex` and other IMPORTED targets, their creation depends on `FindCPLEX.cmake` script which is used by your project. E.g. [that script](https://gitlab.inria.fr/eyrauddu/pmtool/blob/master/FindCPLEX.cmake) doesn't create IMPORTED targets, but sets `CPLEX_LIBRARIES` and `CPLEX_INCLUDE_DIRS` variables (this is written in the description of the script at the beginning). We don't know which `FindCPLEX.cmake` script is used in your project, so it is difficult to help more. – Tsyvarev Jul 03 '20 at 06:39
  • thank you for your advice about asking tips. – Shiny-Sneakers Jul 03 '20 at 06:49
  • Fortunatly, my FindCPLEX.cmake file is same with your link. should i add IMPORT command on file? – Shiny-Sneakers Jul 03 '20 at 06:51
  • This seems unrelated to CPLEX itself. It seems an error in your build system configuration. There is neither a problem with CPLEX binaries or headers nor with code that uses CPLEX. Instead the target `Cplex::Cplex` is not found, which means that it is missing from your cmake setup. – Daniel Junglas Jul 03 '20 at 06:51
  • 1
    If your project uses `FindCPLEX.cmake` similar to [that one](https://gitlab.inria.fr/eyrauddu/pmtool/blob/master/FindCPLEX.cmake), then instead of IMPORTED targets you need to use `CPLEX_INCLUDE_DIRS` variable in `target_include_directories` command and `CPLEX_LIBRARIES` variable in `target_link_libraries` command. (The last variable contains several variables, which *probably* corresponds to `Cplex::Cplex` and `Cpxutils::Lib` targets in your current code). If you want to not change your current code, then you need to find `FindCPLEX.cmake` script which actually creates these IMPORTED targets. – Tsyvarev Jul 03 '20 at 06:58
  • @Tsyvarev It works! i'm very appreciate you! – Shiny-Sneakers Jul 03 '20 at 07:06
  • @Shiny-Sneakers If you resolved the issue, please consider writing an answer post, showing the modified working code, so other viewers can easily see how you fixed the problem, and learn from your post. – Kevin Jul 03 '20 at 13:17

0 Answers0