Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake构建项目,编译报错问题 #125

Open
SoftwareKiller opened this issue Oct 26, 2020 · 3 comments
Open

CMake构建项目,编译报错问题 #125

SoftwareKiller opened this issue Oct 26, 2020 · 3 comments

Comments

@SoftwareKiller
Copy link

环境:ubuntu16.04,gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2~16.04)
Release报错如下:
In file included from /usr/include/string.h:635,
from /usr/include/memory.h:29,
from /home/z/third_lib/behaviac/inc/behaviac/common/memory/memory.h:26,
from /home/z/third_lib/behaviac/src/common/file/listfiles.cpp:14:
In function ‘char* strcat(char*, const char*)’,
inlined from ‘int listfiles_readfile(const listfiles_dir_t*, listfiles_file_t*)’ at /home/z/third_lib/behaviac/src/common/file/listfiles.cpp:211:22:
/usr/include/x86_64-linux-gnu/bits/string3.h:148:33: error: ‘char* __builtin___strcat_chk(char*, const char*, long unsigned int)’ accessing 4097 or more bytes at offsets 0 and 4096 may overlap 1 byte at offset 4096 [-Werror=restrict]
148 | return __builtin___strcat_chk (__dest, __src, __bos (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
CMakeFiles/libbehaviac.dir/build.make:900: recipe for target 'CMakeFiles/libbehaviac.dir/src/common/file/listfiles.cpp.o' failed
make[2]: *** [CMakeFiles/libbehaviac.dir/src/common/file/listfiles.cpp.o] Error 1
CMakeFiles/Makefile2:513: recipe for target 'CMakeFiles/libbehaviac.dir/all' failed
make[1]: *** [CMakeFiles/libbehaviac.dir/all] Error 2
Makefile:102: recipe for target 'all' failed
make: *** [all] Error 2

Win编译,CMake构建,使用VS2019,报错全为:
错误 C2220 以下警告被视为错误 (编译源文件 D:\workplace\behaviac\src\agent\state_t.cpp) libbehaviac C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\algorithm 1310

@scp-166
Copy link

scp-166 commented Jan 16, 2021

cmakeList.txt 里面加上这句试一试
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-fpermissive")

@lemonlittlebaby
Copy link

我把cmakeList.txt里面的这里改了一下,就可以用vs2019编译成功了,但是运行结果是否正确还没有验证,只是能编译成功,你试试
原文:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")

#warning treated as error
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")

我改成:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")

#warning treated as error
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX-")

@hk520570
Copy link

修改CMakelist.txt 中-Werror去掉,这个是把warring当成error了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants