2016-11-22 2 views
0

최근에 C++로 새 프로젝트를 시작했습니다. 문제는 컴파일 할 때 링크 오류가 발생한다는 것입니다. 오늘 하루 종일 디버깅하려했지만 어디서나 좋은 해결책을 찾지 못했습니다. 누군가가 그것을 도울 수 있다면 그것은 놀랄 것입니다. Mac Sierra를 사용하고 있습니다.아키텍처에 대한 기호가 없습니다. x86_64 - Cmake - Mac sierra

parsing/methylation.h

#ifndef EPIRL_METHYLATION_H 
#define EPIRL_METHYLATION_H 

#include <stdio.h> 
#include <iostream> 
#include <fstream> 
#include <vector> 
#include <sstream> 

using namespace std; 

namespace methylation { 
    struct MethLine { 
     string chr; 
     int coord; 
     char strand; 
     int methylated; 
     int un_methylated; 
     string context; 
     string tag; 
    }; 

    string calculateMethylationByContext(
      MethLine m_input[], int length, 
      int window_start, int window_end, int threshold); 

    void calculateMethylation(
     const istream &methylation_stream, 
     const istream &coordinate_stream, 
     const ostream &output_stream 
    ); 
} 

#endif //EPIRL_METHYLATION_H 

parsing/methylation.cpp

#include "methylation.h" 

namespace methylation { 
    string calculateMethylationByContext(
      MethLine m_input[], int length, 
      int window_start, int window_end, int threshold) { 
// rest of the code ... 
    } 
} 

main.cpp

#include <iostream> 
#include <fstream> 
#include "parsing/methylation.h" 

using namespace std; 

int main(int argc, char **argv) { 
    if (argc != 4) { 
     cout << "Invalid number of arguments..." << endl; 
     return 1; 
    } 

    char *methylation_file = argv[1]; 
    char *coordinate_file = argv[2]; 
    char *output_file = argv[3]; 

    ifstream methylation_file_stream(methylation_file, ios::binary); 
    ifstream coordinate_file_stream(coordinate_file, ios::binary); 
    ofstream output_file_stream(output_file, ios::binary); 

    methylation::calculateMethylation(methylation_file_stream, 
         coordinate_file_stream, output_file_stream); 
    methylation_file_stream.close(); 
    coordinate_file_stream.close(); 
    output_file_stream.close(); 

    return 0; 
} 
,745,

코딩에 CLion을 사용합니다. 나는 그것을 구축 할 때, 내 cmake 명령은 잘 작동하지만 내가 다음을 클릭합니다 때 다음과 같은 오류 얻을 '확인'

cmake_minimum_required(VERSION 3.6) 
project(src) 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 

set(SOURCE_FILES 
    parsing/methylation.cpp 
    parsing/methylation.h 
    main.cpp) 

add_executable(src ${SOURCE_FILES}) 
:

Undefined symbols for architecture x86_64: 
    "methylation::calculateMethylation(std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> > const&)", referenced from: 
     _main in main.cpp.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make[3]: *** [src] Error 1 
make[2]: *** [CMakeFiles/src.dir/all] Error 2 
make[1]: *** [CMakeFiles/src.dir/rule] Error 2 
make: *** [src] Error 2 

CMakeLists.txt 파일은 다음과 같습니다를 내가 cmake 명령을 실행하면

, 내 출력은 이것이다 : 자동 cMAKE에 의해 감지

-- The C compiler identification is AppleClang 8.0.0.8000042 
-- The CXX compiler identification is AppleClang 8.0.0.8000042 
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc 
-- Check for working C compiler: /Library/Developer/CommandLineTools/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: /Library/Developer/CommandLineTools/usr/bin/c++ 
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Detecting CXX compile features 
-- Detecting CXX compile features - done 
-- Configuring done 
-- Generating done 
-- Build files have been written to: /Users/sztankatt/Documents/University/PartIII/Project/epiRL/src 
+0

기호에 대한 모든 원본 파일을 검색하십시오. 그런 다음 심볼이 포함 된 소스 파일이 컴파일되고 링크되어 있는지 확인하십시오. 또한 기호가 정적 또는 비공개가 아닌지 확인하십시오. –

+0

당신이 제공하는 코드에서'calculateMethylation'의 ** 정의 **가 보이지 않습니다; 'parsing/methylation.h '에이 함수의 * 선언 * 만있다. – Tsyvarev

+0

'calculateMethylationByContext'와 관련된 내용을 보여주고 있지만 오류는'calculateMethylation'과 관련이 있습니다. 이 함수를 어디에서 정의 했습니까? – nos

답변

0

번 확인하는 컴파일러. 처음 CMAKE를 실행할 때 CMAKE가 알려주는 게시물을 게시 할 수 있습니까?

This may be a hint for your problem, too

+0

안녕하세요! 그냥 내 cmake 명령의 출력을 게시했습니다. 흥미롭게도 methylation.cpp 파일의 내용을 main.cpp에 복사하면 오류없이 코드가 컴파일됩니다. 연결이 제대로 작동하지 않는 것 같습니다. – tomooka

+0

당신은 다음과 같은 때 어떻게되는지 확인할 수 있습니다 target_link_libraries을 (SRC =는/usr/빈/gcc가 -DCMAKE_CXX_COMPILER =는/usr/빈/g ++ –

+0

정확히 같은 오류 :(당신은 다음을 수행하려고 할 수 – tomooka

0

당신의 CMakeLists.txt 괜찮습니다.

@ thomas-matthews @tsyvarev @nos가 주석에 지적한대로 예제 코드에는 methylation::calculateMethylation()의 정의/구현이 없습니다. 당신이보고있는 것은이 상황에서 Apple/clang과 함께 예상되는 실패입니다.

❯ make 
[ 33%] Building CXX object CMakeFiles/src.dir/parsing/methylation.cpp.o 
/Users/nega/foo/parsing/methylation.cpp:8:5: warning: control reaches end of non-void function [-Wreturn-type] 
    } 
    ^
1 warning generated. 
[ 66%] Building CXX object CMakeFiles/src.dir/main.cpp.o 
[100%] Linking CXX executable src 
Undefined symbols for architecture x86_64: 
    "methylation::calculateMethylation(std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> > const&)", referenced from: 
     _main in main.cpp.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make[2]: *** [src] Error 1 
make[1]: *** [CMakeFiles/src.dir/all] Error 2 
make: *** [all] Error 2 

성공적으로 완료 make을 허용하는 더미 구현을 추가하거나 main.cpp에 호출을 주석.

당신이

이의 당신이 (아마도 다른 파일) 코드에 methylation::calculateMethylation()의 구현을해야합니까 가정 해 봅시다 올바른 구현을 가정. CMake 생성 Makefile에서 빌드 오류를 디버깅하는 첫 번째 단계는 make 변수 VERBOSE을 true 값 (예 : make VERBOSE=1)으로 설정하여 실행하는 것입니다.

❯ make VERBOSE=1 
/usr/local/Cellar/cmake/3.7.0/bin/cmake -H/Users/nega/foo -B/Users/nega/foo/build --check-build-system CMakeFiles/Makefile.cmake 0 
/usr/local/Cellar/cmake/3.7.0/bin/cmake -E cmake_progress_start /Users/nega/foo/build/CMakeFiles /Users/nega/foo/build/CMakeFiles/progress.marks 
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all 
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/src.dir/build.make CMakeFiles/src.dir/depend 
cd /Users/nega/foo/build && /usr/local/Cellar/cmake/3.7.0/bin/cmake -E cmake_depends "Unix Makefiles" /Users/nega/foo /Users/nega/foo /Users/nega/foo/build /Users/nega/foo/build /Users/nega/foo/build/CMakeFiles/src.dir/DependInfo.cmake --color= 
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/src.dir/build.make CMakeFiles/src.dir/build 
[ 33%] Building CXX object CMakeFiles/src.dir/parsing/methylation.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -std=gnu++11 -o CMakeFiles/src.dir/parsing/methylation.cpp.o -c /Users/nega/foo/parsing/methylation.cpp 
/Users/nega/foo/parsing/methylation.cpp:8:5: warning: control reaches end of non-void function [-Wreturn-type] 
    } 
    ^
1 warning generated. 
[ 66%] Building CXX object CMakeFiles/src.dir/main.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -std=gnu++11 -o CMakeFiles/src.dir/main.cpp.o -c /Users/nega/foo/main.cpp 
[100%] Linking CXX executable src 
/usr/local/Cellar/cmake/3.7.0/bin/cmake -E cmake_link_script CMakeFiles/src.dir/link.txt --verbose=1 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/src.dir/parsing/methylation.cpp.o CMakeFiles/src.dir/main.cpp.o -o src 
Undefined symbols for architecture x86_64: 
    "methylation::calculateMethylation(std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> > const&)", referenced from: 
     _main in main.cpp.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make[2]: *** [src] Error 1 
make[1]: *** [CMakeFiles/src.dir/all] Error 2 
make: *** [all] Error 2 

이제 링크 단계를보고 누락 된 항목이 있는지 확인할 수 있습니다. 라이브러리 또는 오브젝트 파일 일 수 있습니다.

❯ make VERBOSE=1 

것은이 줄 것이다 : 그렇다면하면, 이제 돌아가서 CMake와 함께 예상치 못한 빌드 실패를 디버깅하는 첫 번째 단계는 메이크 생성

당신의 CMakeLists.txt

요약에 추가 아는 것은 실행하는 것입니다 당신은 CMake가 무대 뒤에서 무엇을하고 있는지 알 수 있습니다.

관련 문제