2017-10-15 9 views
0

나는 누구의 설치 지침 다음과 같다 프로젝트 (일부 C++로, 주로 C)는 CMake 있습니다.CMake 프로젝트를 특정 방식으로 컴파일하도록 IDE에 알리는 방법은 무엇입니까? 내가 명령 줄에서 컴파일하는 경우</p> <pre><code>mkdir build cd build cmake /*some options*/ ../ make </code></pre> <p>이 완벽하게 작동합니다 :

이 프로그램을 컴파일하여 그래픽 디버거로 디버깅 할 수 있도록 IDE를 사용하고 싶습니다. 그러나 IDE를 사용하여 컴파일하려고하면 링커 오류가 발생합니다.

CMake의 내부 동작에 익숙하지 않아 원하는 동작을 얻는 방법을 모르겠습니다. 사실, 이것이 CMake 질문이라면 나는 확신 할 수 없다. 아마 이것은 IDE 설정의 문제 일 것입니다. 도움이된다면, 제가 사용하는 IDE는 JetBrains의 Clion입니다.

IDE에서 주어진 오류

은 CMake 파일

set(CMAKE_CXX_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c++") 
set(CMAKE_C_COMPILER "/Library/Developer/CommandLineTools/usr/bin/cc") 
project(mpmc) 
cmake_minimum_required(VERSION 3.8) 
option(MPI "Use MPI to parallelize the calculations (requires MPI)" OFF) 
option(CUDA "Use CUDA to offload polarization calculations to a GPU (requires CUDA)" OFF) 
option(OPENCL "Use OpenCL to offload polarization calculations to a GPU (requires OpenCL)" OFF) 
option(QM_ROTATION "Enable Quantum Mechanics Rigid Rotator calculations (requires LAPACK)" OFF) 
option(VDW "Enable Coupled-Dipole Van der Waals (requires LAPACK)" OFF) 


configure_file (
"${PROJECT_SOURCE_DIR}/src/include/cmake_config.h.in" 
"${PROJECT_BINARY_DIR}/src/include/cmake_config.h" 
) 

set(CMAKE_BUILD_TYPE Release) 

if(CMAKE_COMPILER_IS_GNUCC) 
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall") 
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall") 
endif() 

set(LIB m) 

set(INCLUDE src/include/ src/mersenne/ ${PROJECT_BINARY_DIR}/src/include) 

set(SRC 
src/mc/mc_moves.c 
src/mc/surface_fit_arbitrary.c 
src/mc/qshift.c 
src/mc/single_point.c 
src/mc/mc.c 
src/mc/replay.c 
src/mc/pimc.c 
src/mc/surface.c 
src/mc/surf_fit.c 
src/mc/fugacity.c 
src/mc/cavity.c 
src/mc/checkpoint.c 
src/histogram/histogram.c 
src/energy/lj_buffered_14_7.c 
src/energy/bessel.c 
src/energy/dreiding.c 
src/energy/energy.c 
src/energy/polar.c 
src/energy/pbc.c 
src/energy/disp_expansion.c 
src/energy/vdw.c 
src/energy/pairs.c 
src/energy/bond.c 
src/energy/coulombic_gwp.c 
src/energy/exp_repulsion.c 
src/energy/coulombic.c 
src/energy/sg.c 
src/energy/lj.c 
src/energy/axilrod_teller.cpp 
src/mersenne/mt.c 
src/mersenne/dSFMT.h 
src/mersenne/dSFMT.c 
src/mersenne/dSFMT-common.h 
src/mersenne/dSFMT-params.h 
src/main/quaternion.c 
src/main/CArng.c 
src/main/memnullcheck.c 
src/main/main.c 
src/main/cleanup.c 
src/main/usefulmath.c 
src/io/dxwrite.c 
src/io/simulation_box.c 
src/io/average.c 
src/io/output.c 
src/io/check_input.c 
src/io/input.c 
src/io/mpi.c 
src/io/read_pqr.c 
src/io/setup_ocl.c 
src/polarization/thole_field.c 
src/polarization/polar_wolf_lookup.c 
src/polarization/thole_polarizability.c 
src/polarization/thole_matrix.c 
src/polarization/polar_ewald.c 
src/polarization/thole_iterative.c 
) 

if(MPI) 
    message("-- MPI Enabled") 
    find_package(MPI REQUIRED) 
    if(NOT MPI_C_FOUND) 
     message(FATAL_ERROR "-- MPI not found! Exiting ...") 
    endif() 
    set(INCLUDE ${INCLUDE} ${MPI_C_INCLUDE_PATH}) 
    set(LIB ${LIB} ${MPI_C_LIBRARIES}) 
else() 
    message("-- MPI Disabled") 
endif() 

if(CUDA) 
    message("-- CUDA Enabled") 
    find_package(CUDA REQUIRED) 
    set(SRC ${SRC} src/polarization_gpu/polar_cuda.cu) 
else() 
    message("-- CUDA Disabled") 
endif() 

if(OPENCL) 
    message("-- OpenCl Enabled") 
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) 
    find_package(OpenCL REQUIRED) 
    if(NOT OPENCL_FOUND) 
     message(FATAL_ERROR "--OpenCl not found! Exiting ...") 
    endif() 
    set(SRC ${SRC} 
     src/polarization_gpu/polar_ocl.c 
     src/io/setup_ocl.c) 
    set(INCLUDE ${INCLUDE} ${OpenCL_INCLUDE_DIRS}) 
    set(LIB ${LIB} ${OpenCL_LIBRARIES}) 
else() 
    message("-- OpenCl Disabled") 
endif() 

if(QM_ROTATION) 
    message("-- QM Rotation Enabled") 
    set(SRC ${SRC} 
     src/quantum_rotation/rotational_basis.c 
     src/quantum_rotation/rotational_eigenspectrum.c 
     src/quantum_rotation/rotational_integrate.c 
     src/quantum_rotation/rotational_potential.c) 
    set(LIB ${LIB} lapack) 
else() 
    message("-- QM Rotation Disabled") 
endif() 

if(VDW) 
    message("-- CDVDW Enabled") 
    if(NOT QM_ROTATION) 
     set(LIB ${LIB} lapack) 
    endif() 
else() 
    message("-- CDVDW Disabled") 
endif() 

include_directories(${INCLUDE}) 
if(CUDA) 
    cuda_add_executable(${PROJECT_NAME} ${SRC}) 
else() 
    add_executable(${PROJECT_NAME} ${SRC}) 
endif() 
target_link_libraries(${PROJECT_NAME} ${LIB}) 

if(MPI) 
    if(MPI_C_COMPILE_FLAGS) 
     set_target_properties(${PROJECT_NAME} PROPERTIES 
     COMPILE_FLAGS "${MPI_C_COMPILE_FLAGS}") 
    endif() 

    if(MPI_C_LINK_FLAGS) 
     set_target_properties(${PROJECT_NAME} PROPERTIES 
     LINK_FLAGS "${MPI_C_LINK_FLAGS}") 
    endif() 
endif() 

입니다 IDE_error

입니다 그리고 디렉토리 구조는 directory_structure

+0

문제를 재현하는 'CMakeLists.txt'의 예제를 제공하거나 링커 오류가 도움이 될 수도 있습니다. –

+0

@Cinder 비스킷은 유감입니다. 정보가 추가되었습니다. – Luciano

답변

2
당신은 당신의 명령 행 컴파일에서 빌드 디렉토리에 CLion를 가리킬 수 있습니다

. "File -> Settings -> Build, Execution, ... -> Cmake"로 이동하여 "generation path"를 "original"빌드 디렉토리로 지정하십시오. 그렇지 않으면 Clion은 "cmake-build-debug"에서 자체 dir을 생성합니다. CLION을 다른 디렉토리로 가리킨 후에도 동일한 설정 탭의 "Debug/Release"Configuration과 같은 다른 매개 변수에 따라 cmake 변수가 변경 될 수 있습니다. cmake 설정 이후로 우리는 "Release"가 기본값임을 알 수 있습니다. 단지 빌드 디렉토리를 전환하지 않고도 잠재적으로 차이를 만들 수 있습니다.