使用GCC时,CLion调试器无法正常工作 [英] CLion debugger not working when using gcc
问题描述
我正在尝试配置CLion,以便可以使用openMP.在Mac上使用默认设置时,编译器为clang.默认的Apple clang不支持openMP.
Im trying to configure CLion so that I can use openMP. When using the default settings on my Mac, the compiler is clang. Default Apple clang does not support openMP.
当我将编译器更改为GCC时,调试器不会在断点处停止.该程序将像执行编译文件时那样运行.
When I change my compiler to GCC, the debugger will not stop at breakpoints. The program just runs as it would when executing the compiled file.
下面的CMakeLists.txt文件可与CLion调试器完美配合.当我取消注释编译器标志时,调试器将忽略断点.
The CMakeLists.txt file below works perfectly with CLion debugger. When I uncomment out the compiler flags, the debugger ignores the breakpoints.
cmake_minimum_required(VERSION 3.8)
project(CLionTest)
set(CMAKE_C_STANDARD 99)
#set(CMAKE_C_COMPILER /usr/local/bin/gcc-7)
#set(CMAKE_C_FLAGS -fopenmp)
#set(CMAKE_C_FLAGS_DEBUG "-D_DEBUG")
set(MAIN main.c)
add_executable(CLionTest ${MAIN})
add_custom_target(CLionTestMake COMMAND make all WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
我该如何解决?
工具链设置:CMake可执行文件:捆绑的CMake 3.8.2调试器:捆绑的LLDB 3.9.0
Toolchain settings: CMake executable: Bundeled CMake 3.8.2 Debugger: Bundled LLDB 3.9.0
main.c:
#include <stdio.h>
#include <unistd.h>
#ifdef _OPENMP
#include <omp.h>
#endif
int main() {
printf("Hello, World!\n");
#pragma omp parallel
{
#ifdef _OPENMP
int size = omp_get_num_threads();
int rank = omp_get_thread_num();
#else
int rank = 0;
int size = 1;
#endif
printf("%d/%d\n", rank, size);
};
return 0;
}
推荐答案
set(CMAKE_C_FLAGS -fopenmp)
set(CMAKE_C_FLAGS_DEBUG "-D_DEBUG")
您要替换C标志而不是附加C标志,因此要删除生成调试符号的内置 -g
选项.相反,
You are replacing the C flags instead of appending them, so you are dropping the builtin -g
option that generates debug symbols. Instead, do
set(CMAKE_C_FLAGS "${CMAKE_CFLAGS} -fopenmp")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
这篇关于使用GCC时,CLion调试器无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!