在cygwin中使用文件系统时遇到了提升问题。错误发生在这个简单的代码部分:
1000000007
链接期间发生以下错误:
int foo(int n)
{
if (n < 30) return 1 << n;
int re = (1 << 30) % 1000000007;
for(int i=31; n>i; i++)
{
re <<= 1;
if (re > 1000000007) re -= 1000000007;
}
return re;
}
我认为这是32/64位问题,但我不知道如何解决它......
PS没有。 1
CMake还警告我前方的问题(尽管没有错误)。这是相关的摘录:
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <fstream>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
using namespace boost::filesystem;
int main(int argc, char **argv)
{
path targetDir("/cygdrive/d/Repositories/testmodels/");
if (exists(targetDir)) {
cout << "directory exists!" << endl;
directory_iterator end_itr; // default construction yields past-the-end
for (directory_iterator itr(targetDir); itr != end_itr; ++itr)
{
cout << *itr << endl;
}
}
}
所以我使用CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text+0x4d3): undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)'
CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text+0x4d3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::dir_itr_close(void*&)'
CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text$_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv[_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv]+0x18): undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)'
CMakeFiles/test.dir/main.cpp.o:main.cpp:(.text$_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv[_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv]+0x18): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::dir_itr_close(void*&)'
collect2: fout: ld gaf exit-status 1 terug
make[2]: *** [test/CMakeFiles/test.dir/build.make:454: test/test.exe] Error 1
make[2]: Directory '/cygdrive/d/Repositories/test/build' exited
make[1]: *** [CMakeFiles/Makefile2:144: test/CMakeFiles/test.dir/all] Error 2
make[1]: Directory '/cygdrive/d/Repositories/test/build' exited
make: *** [Makefile:98: all] Error 2
重新运行,警告消息消失,但错误仍然存在。
PS没有。 2
在上面的代码中注释掉for循环会使链接错误消失。不知道这是怎么发生的......
有什么建议吗?
UPDATE: Boost与Cygwin安装程序一起安装。我在Cygwin和Cygwin64都尝试过这个。下面附加了CMakeLists.txt(可执行文件在src /子目录中的单独CMakeLists文件中创建,这在这里并不重要。)
的CMakeLists.txt:
-- The CXX compiler identification is GNU 6.4.0
CMake Warning at /usr/share/cmake-3.6.2/Modules/Platform/CYGWIN.cmake:15 (message):
CMake no longer defines WIN32 on Cygwin!
(1) If you are just trying to build this project, ignore this warning or
quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in
the CMake cache. If later configuration or build errors occur then this
project may have been written under the assumption that Cygwin is WIN32.
In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead.
(2) If you are developing this project, add the line
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
at the top of your top-level CMakeLists.txt file or set the minimum
required version of CMake to 2.8.4 or higher. Then teach your project to
build on Cygwin without WIN32.
答案 0 :(得分:0)
尝试在Cygwin终端中安装boost库或尝试通过Cygwin安装程序安装boost(更简单)。 如果它没有帮助,请显示您的CMakeLists文件。