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

CMakeLists.txt: “-DCMAKE_EXPORT_COMPILE_COMMANDS=1”不应该放在此处. #1

Closed
tyn1998 opened this issue Oct 16, 2021 · 1 comment · Fixed by #182
Closed

CMakeLists.txt: “-DCMAKE_EXPORT_COMPILE_COMMANDS=1”不应该放在此处. #1

tyn1998 opened this issue Oct 16, 2021 · 1 comment · Fixed by #182

Comments

@tyn1998
Copy link

tyn1998 commented Oct 16, 2021

miniob的小伙伴们你们好,我使用vim搭配coc.nvim以及clangd实现c/c++的自动补全,因此对compile_commands.json有需求。

当前的CMakeLists.txt已经涉及compile_commands.json的生成,但是这个FLAG的位置应该摆错了。

SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -Wall -DCMAKE_EXPORT_COMPILE_COMMANDS=1")

虽然CMAKE_COMMON_FLAGS这个变量感觉上是设置了cmake的FLAGS,但是最后其实是赋值给了CMAKE_CXX_FLAGS,而-DCMAKE_EXPORT_COMPILE_COMMANDS=1这个参数是用在cmake上的,而不是gcc

解决方法是:

1、在CMakeLists.txt开头位置附近加上set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

2、或在运行cmake时加上参数,即cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..

这样就能生成compile_commands.json
image

@hnwyllmm
Copy link
Collaborator

能不能提个PR?
等大赛结束,会继续演进miniob

hnwyllmm added a commit that referenced this issue May 24, 2023
### What problem were solved in this pull request?

Issue Number: close #91 close #1 

Problem:
编译时编译器抛出的一些告警信息可以帮我们避免很多问题,但是现在并没有利用这个特性

### What is changed and how it works?
CMake中增加-Werror编译选项

### Other information
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

Successfully merging a pull request may close this issue.

2 participants