모든 것에 대한 CMake + MSys2 정의되지 않은 참조 (C ++ 런타임 포함)

마이크 존 해리

저는 크로스 플랫폼 C ++ 프로젝트를 개발하고 있습니다. Linux에서는 잘 구축되지만 Windows (10) + MSys2에서는 이상한 문제가 발생했습니다. 컴파일은 잘 작동하지만 (내 include dirs 등을 선택합니다.) 내가 가지고있는 정적 가져온 라이브러리와 C ++ 런타임에 대한 모든 종류의 정의되지 않은 참조 오류로 인해 연결이 실패합니다.

CMAKE_C [XX] _COMPILER, CMAKE_MAKE_PROGRAM 설정을 시도했지만 구성 단계의 출력은 항상 동일합니다.

$ cmake ..
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /mingw64/bin/CC.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: <....>

앞서 언급했듯이 컴파일은 작동하지만 실행 파일 연결은 눈에 띄게 실패합니다. 다음은 최소한의 작업 예입니다.

$ cat ../CMakeLists.txt
project(example)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_executable(example
        main.cpp
)

다음은 출력 샘플입니다 (나머지는 간결함을 위해 생략 됨).

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::Init()'

cmake에 -v를 추가하면 다음 명령이 생성됩니다.

엮다:

/mingw64/bin/CC.exe   -std=gnu++17 -o CMakeFiles/example.dir/main.cpp.obj -c /home/.../Development/minex/main.cpp

링크:

/mingw64/bin/CC.exe CMakeFiles/example.dir/main.cpp.obj -o example

CC.exe가 꺼진 것 같고 CXX 컴파일러 플래그를 설정하거나 설정하지 않으면 사용됩니다.

또한 "MSYS2 Makefiles"생성을 시도했지만 실패했습니다 (생성기를 알지 못함).

실행하는 것으로 출력을 재현 할 수 있습니다

$ CC main.cpp -o example

동안

$ g++ main.cpp -o example

잘 작동합니다.

CMake 버전은 3.18.4입니다.

편집 : 이것은 실행의 전체 출력입니다 make VERBOSE=1( mingw64-cmake'입력 디렉토리'와 '이탈 디렉토리'경로가 절대 Windows 경로 임을 제외하고는 동일한 출력을 생성하는 것 같습니다) :

    $ cat log
/usr/bin/cmake.exe -S/home/<...>/Development/minex -B/home/<...>/Development/minex/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake.exe -E cmake_progress_start /home/<...>/Development/minex/build/CMakeFiles /home/<...>/Development/minex/build//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/<...>/Development/minex/build'
make  -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/depend
make[2]: Entering directory '/home/<...>/Development/minex/build'
cd /home/<...>/Development/minex/build && /usr/bin/cmake.exe -E cmake_depends "Unix Makefiles" /home/<...>/Development/minex /home/<...>/Development/minex /home/<...>/Development/minex/build /home/<...>/Development/minex/build /home/<...>/Development/minex/build/CMakeFiles/example.dir/DependInfo.cmake --color=
Dependee "/home/<...>/Development/minex/build/CMakeFiles/example.dir/DependInfo.cmake" is newer than depender "/home/<...>/Development/minex/build/CMakeFiles/example.dir/depend.internal".
Dependee "/home/<...>/Development/minex/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/<...>/Development/minex/build/CMakeFiles/example.dir/depend.internal".
Scanning dependencies of target example
make[2]: Leaving directory '/home/<...>/Development/minex/build'
make  -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/build
make[2]: Entering directory '/home/<...>/Development/minex/build'
[ 50%] Building CXX object CMakeFiles/example.dir/main.obj
/mingw64/bin/CC.exe   -std=gnu++17 -o CMakeFiles/example.dir/main.obj -c /home/<...>/Development/minex/main.cpp
[100%] Linking CXX executable example
/usr/bin/cmake.exe -E cmake_link_script CMakeFiles/example.dir/link.txt --verbose=1
/mingw64/bin/CC.exe CMakeFiles/example.dir/main.obj -o example
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x23): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x32): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.rdata$.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_[.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_]+0x0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/example.dir/build.make:103: example] Error 1
make[2]: Leaving directory '/home/<...>/Development/minex/build'
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/example.dir/all] Error 2
make[1]: Leaving directory '/home/<...>/Development/minex/build'
make: *** [Makefile:103: all] Error 2

해결책:

CMAKE_CXX_COMPILER를 잘못 설정했습니다 : /. 나는 기억에서 그것을하고 있었고

CMAKE_CXX_COMPILER=... cmake ..

아니

cmake .. -DCMAKE_CXX_COMPILER=...

하나! CC가 cpp 파일을 성공적으로 컴파일하는 데 사용되는 것이 여전히 이상하지만 개체 파일을 연결할 수 없습니다.

Yflelion

ac 컴파일러로 C ++ 프로그램을 컴파일 / 링크하려고하기 때문에 이러한 오류가 발생합니다. 예를 들어 언급 한 두 개의 정의되지 않은 참조는 libstdc ++의 일부입니다. 를 사용할 때 기본적으로 사용 g++되지만 CC. CC를 사용하려면 수동으로 추가해야 -lstdc++합니다.

가장 쉬운 방법은 g ++를 사용하여 C ++ 프로그램을 컴파일하고 링크하는 것입니다.

어떤 이유로 /mingw64/bin/CC.exe는 CXX 컴파일러로 간주되며 작동 감지를 건너 뜁니다. 작업 감지 건너 뛰기를 방지하려면 추가 할 수 있습니다 set(CMAKE_CXX_COMPILER_WORKS 1). 컴파일러를 수정하려면 CMAKE_CXX_COMPILER에CMAKE_CXX_COMPILER 설명 된 대로 설정하거나 CXX에CXX 설명 된대로 설정할 수 있습니다 . 캐시를 청소할 때주의하십시오.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

C ++의 모든 함수에 대한 정의되지 않은 참조

분류에서Dev

C ++의 함수에 대한 정의되지 않은 참조

분류에서Dev

함수에 대한 정의되지 않은 참조? C ++

분류에서Dev

함수 c에 대한 정의되지 않은 참조

분류에서Dev

함수에 대한 정의되지 않은 참조 (C ++)

분류에서Dev

C ++ : void 함수에 대한 정의되지 않은 참조

분류에서Dev

CMake CUDA C ++ 연결 오류-`someFunction ()`에 대한 정의되지 않은 참조

분류에서Dev

구조체 포인터에 대한 ANSI C 메모리 할당으로 치명적이지 않은 런타임 오류가 발생 함

분류에서Dev

CMAKE를 사용하는 " 'FT_Load_Glyph'에 대한 정의되지 않은 참조"및 기타 SDL2_ttf 함수

분류에서Dev

CUDA catkin / cmake-`curandCreateGenerator`에 대한 정의되지 않은 참조

분류에서Dev

C 헤더의 한 함수에 대한 "정의되지 않은 참조"

분류에서Dev

C 프로그램의 함수에 대한 정의되지 않은 참조

분류에서Dev

C와 C ++ 혼합 ... 함수에 대한 정의되지 않은 참조

분류에서Dev

pngfix.c : 2151 :`inflateReset2 '에 대한 정의되지 않은 참조

분류에서Dev

클래스에 대한 C ++ 정의되지 않은 참조 (1 헤더 2 cpp)

분류에서Dev

정적 함수에 대한 정의되지 않은 참조

분류에서Dev

정적 함수에 대한 정의되지 않은 참조

분류에서Dev

main ()의 함수에 대한 정의되지 않은 참조

분류에서Dev

c 헤더 파일에 대한 정의되지 않은 참조

분류에서Dev

C ++ : 생성자에 대한 정의되지 않은 참조

분류에서Dev

C ++ : ERROR에 대한 정의되지 않은 참조

분류에서Dev

'WinMain @ 16'에 대한 정의되지 않은 참조 (C ++)

분류에서Dev

"Class :: method"C ++에 대한 정의되지 않은 참조?

분류에서Dev

aruco 함수에 대한 정의되지 않은 참조

분류에서Dev

'cusolverDn'함수에 대한 정의되지 않은 참조

분류에서Dev

portaudio 함수에 대한 gcc 정의되지 않은 참조

분류에서Dev

기존 함수에 대한 정의되지 않은 참조

분류에서Dev

'함수'에 대한 정의되지 않은 참조

분류에서Dev

내 함수에 대한 정의되지 않은 참조

Related 관련 기사

  1. 1

    C ++의 모든 함수에 대한 정의되지 않은 참조

  2. 2

    C ++의 함수에 대한 정의되지 않은 참조

  3. 3

    함수에 대한 정의되지 않은 참조? C ++

  4. 4

    함수 c에 대한 정의되지 않은 참조

  5. 5

    함수에 대한 정의되지 않은 참조 (C ++)

  6. 6

    C ++ : void 함수에 대한 정의되지 않은 참조

  7. 7

    CMake CUDA C ++ 연결 오류-`someFunction ()`에 대한 정의되지 않은 참조

  8. 8

    구조체 포인터에 대한 ANSI C 메모리 할당으로 치명적이지 않은 런타임 오류가 발생 함

  9. 9

    CMAKE를 사용하는 " 'FT_Load_Glyph'에 대한 정의되지 않은 참조"및 기타 SDL2_ttf 함수

  10. 10

    CUDA catkin / cmake-`curandCreateGenerator`에 대한 정의되지 않은 참조

  11. 11

    C 헤더의 한 함수에 대한 "정의되지 않은 참조"

  12. 12

    C 프로그램의 함수에 대한 정의되지 않은 참조

  13. 13

    C와 C ++ 혼합 ... 함수에 대한 정의되지 않은 참조

  14. 14

    pngfix.c : 2151 :`inflateReset2 '에 대한 정의되지 않은 참조

  15. 15

    클래스에 대한 C ++ 정의되지 않은 참조 (1 헤더 2 cpp)

  16. 16

    정적 함수에 대한 정의되지 않은 참조

  17. 17

    정적 함수에 대한 정의되지 않은 참조

  18. 18

    main ()의 함수에 대한 정의되지 않은 참조

  19. 19

    c 헤더 파일에 대한 정의되지 않은 참조

  20. 20

    C ++ : 생성자에 대한 정의되지 않은 참조

  21. 21

    C ++ : ERROR에 대한 정의되지 않은 참조

  22. 22

    'WinMain @ 16'에 대한 정의되지 않은 참조 (C ++)

  23. 23

    "Class :: method"C ++에 대한 정의되지 않은 참조?

  24. 24

    aruco 함수에 대한 정의되지 않은 참조

  25. 25

    'cusolverDn'함수에 대한 정의되지 않은 참조

  26. 26

    portaudio 함수에 대한 gcc 정의되지 않은 참조

  27. 27

    기존 함수에 대한 정의되지 않은 참조

  28. 28

    '함수'에 대한 정의되지 않은 참조

  29. 29

    내 함수에 대한 정의되지 않은 참조

뜨겁다태그

보관