我试图按照this示例熟悉我的自己与Cmake: 简而言之,我有这个c ++代码。我想使用Cmake为此代码生成一个makefile,然后运行makefile。不幸的是,生成的Makefile发出错误。我正在使用Windows 7
以下是我正在使用的代码
文件:main.cpp
#include "ToDo.h"
int main( int argc, char** argv)
{
ToDo list;
return 0;
}
文件:ToDo.h
#ifndef TODO_H
#define TODO_H
class ToDo
{
public:
ToDo();
~ToDo();
};
文件:ToDo.cpp
#include "ToDo.h"
ToDo::ToDo()
{
}
ToDo::~ToDo()
{
}
#endif // TODO_H
这是我的 CMakeLists.txt
project("To Do List")
add_executable(toDo main.cpp ToDo.cpp)
以下是我在cygwin中所做的事情
admin@US01WKS03044 /cygdrive/c/CmakeTest/build
$ cmake -G "Unix Makefiles" ..
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: C:/cygwin64/bin/cc
-- Check for working C compiler: C:/cygwin64/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working CXX compiler: C:/cygwin64/bin/c++.exe
-- Check for working CXX compiler: C:/cygwin64/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - failed
-- Configuring done
-- Generating done
-- Build files have been written to: C:/CmakeTest/build
admin@US01WKS03044 /cygdrive/c/CmakeTest/build
$ ls
cmake_install.cmake CMakeCache.txt CMakeFiles Makefile
admin@US01WKS03044 /cygdrive/c/CmakeTest/build
$ make VERBOSE=1
"C:/Program Files (x86)/CMake/bin/cmake.exe" -HC:/CmakeTest -BC:/CmakeTest/build --check-build-system CMakeFiles/Makefile.cmake 0
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_start C:/CmakeTest/build/CMakeFiles C:/CmakeTest/build/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/cygdrive/c/CmakeTest/build'
/usr/bin/make -f CMakeFiles/toDo.dir/build.make CMakeFiles/toDo.dir/depend
make[2]: Entering directory `/cygdrive/c/CmakeTest/build'
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_depends "Unix Makefiles" C:/CmakeTest C:/CmakeTest C:/CmakeTest/build C:/CmakeTest/build C:/CmakeTest/build/CMakeFiles/toDo.dir/DependInfo.cmake --color=
Dependee "C:/CmakeTest/build/CMakeFiles/toDo.dir/DependInfo.cmake" is newer than depender "C:/CmakeTest/build/CMakeFiles/toDo.dir/depend.internal".
Dependee "C:/CmakeTest/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/CmakeTest/build/CMakeFiles/toDo.dir/depend.internal".
Scanning dependencies of target toDo
make[2]: Leaving directory `/cygdrive/c/CmakeTest/build'
/usr/bin/make -f CMakeFiles/toDo.dir/build.make CMakeFiles/toDo.dir/build
make[2]: Entering directory `/cygdrive/c/CmakeTest/build'
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report C:/CmakeTest/build/CMakeFiles 1
[ 50%] Building CXX object CMakeFiles/toDo.dir/main.cpp.o
C:/cygwin64/bin/c++.exe -o CMakeFiles/toDo.dir/main.cpp.o -c C:/CmakeTest/main.cpp
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report C:/CmakeTest/build/CMakeFiles 2
[100%] Building CXX object CMakeFiles/toDo.dir/ToDo.cpp.o
C:/cygwin64/bin/c++.exe -o CMakeFiles/toDo.dir/ToDo.cpp.o -c C:/CmakeTest/ToDo.cpp
Linking CXX executable toDo.exe
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E remove -f CMakeFiles/toDo.dir/objects.a
C:/cygwin64/bin/ar.exe cr CMakeFiles/toDo.dir/objects.a @CMakeFiles/toDo.dir/objects1.rsp
C:/cygwin64/bin/c++.exe -Wl,--whole-archive CMakeFiles/toDo.dir/objects.a -Wl,--no-whole-archive -o toDo.exe -Wl,--out-implib,libtoDo.dll.a -Wl,--major-image-version,0,--minor-image-version,0
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../lib/libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.33-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain'
/usr/src/debug/cygwin-1.7.33-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status
make[2]: *** [toDo.exe] Error 1
make[2]: Leaving directory `/cygdrive/c/CmakeTest/build'
make[1]: *** [CMakeFiles/toDo.dir/all] Error 2
make[1]: Leaving directory `/cygdrive/c/CmakeTest/build'
make: *** [all] Error 2
为什么Makefile会失败?
答案 0 :(得分:0)
错误意味着编译器正在寻找WinMain
作为可执行文件的入口点,而不是经典的main
,并且它无法找到它。
因为我不使用cygwin,所以不能说出原因(WinMain是特定于windows gui应用程序,如果我没有误会),但你可以重命名{{1转到main
并查看它是否有效。或者查看http://log4aj.blogspot.ro/2010/11/cygwin-gcc-undefined-reference-to.html。