我有一个项目,我仍在尝试使用Clang和Visual Studio在Windows上进行设置。需要说明的是,我曾经参与过几个c++项目,但它们都是成熟的项目,我没有参与设置make文件或解决依赖关系的工作,因此我想要一些这方面的经验。
需要澄清的是,我不使用Visual Studio中内置的LLVM。我的目标是让Visual Studio成为一个便利工具,而不是使用CMake构建项目。
到目前为止,我有一个包含单个nmake项目的解决方案。这个nmake项目调用一个build.bat文件,该文件又调用一个make文件。这个make文件长这样:
你会注意到我已经包含了
需要澄清的是,我不使用Visual Studio中内置的LLVM。我的目标是让Visual Studio成为一个便利工具,而不是使用CMake构建项目。
到目前为止,我有一个包含单个nmake项目的解决方案。这个nmake项目调用一个build.bat文件,该文件又调用一个make文件。这个make文件长这样:
# Based on PUXAN tutorial
# http://www.puxan.com/web/howto-write-generic-makefiles/
# Compiler choice
CC = clang++ -g -O0
CC_OBJ_FLAGS = -w -v -c
# Name of our executable and also the main run target
EXEC = ../bin/output.exe
# Here we get every cpp file in the source directory to make a list of source files
SOURCES = $(wildcard ../src/*.cpp)
# Here we have mapped all the cpp files to o files and now have a list of o files
TMP_OBJECTS = $(SOURCES:.cpp=.o)
OBJECTS = $(foreach obj,$(TMP_OBJECTS),$(subst src,obj,$(obj)))
INC = -I../lib/glfw-3.2.1/include
LINK = -L../lib/glfw-3.2.1/lib-vc2015 -lglfw3dll -lglfw3 -lopengl32
# compile list of o files into executable
# NOTE: when make is run without a target, the first target is chosen. This target
# should remain the first at all times
$(EXEC): $(OBJECTS)
$(CC) $(LINK) $(OBJECTS) -o $(EXEC)
# As each o file becomes a target, compile the associated cpp file into the o file
../obj/%.o: ../src/%.cpp
$(CC) $(CC_OBJ_FLAGS) $(INC) $< -o $@
# Remove the entire list of objects and the executable
clean:
rm -f $(EXEC) $(OBJECTS)
rebuild:
make -B
你会注意到我已经包含了
-g
和-O0
标志,这应该输出符号表,确实,我为output.exe
(以及所有o文件但稍后可以清理)生成了一个pdb
文件。然而,当我在Visual Studio中调试项目时,它显示模块的符号已加载,但断点没有命中,我认为这是指pdb
没有引用源代码。以下是Visual Studio中的调试输出:'output.exe' (Win32): Loaded 'W:\Scratch\Engine\bin\output.exe'. Symbols loaded.
关于Clang的帖子在2016年及之前提到它尚未生成PDB文件,但这是正在进行中的工作。而且,Clang兼容性站点(https://clang.llvm.org/docs/MSVCCompatibility.html)提到调试信息仍在不断完善,但我应该能够使用/Z
和7
或i
生成CodeView信息。我已经尝试将/Zi
和/Z7
都传递给Clang和链接器,但Clang会抱怨,链接器则忽略并发出警告。这份文档声称来自Clang 6,但据我所知,Clang 6尚未发布,属于实验性质。然而,使用带有-g
标志的Clang 4.0,我确实能够生成文件。
是否有人有更多相关信息?我是否遗漏了正确提供源代码的标志或者在Visual Studio中错过了一些设置?我尝试在项目和解决方案级别手动设置源代码,但没有效果。我应该使用某种pdb查看器查看pdb文件并查看源代码路径是否存在吗?
提前感谢任何帮助。
-g
标志与-gcodeview
一起使用是有效的,而仅使用-gcodeview
则不足够。我怎么会错过这个标志,为什么文档没有将此标志与-g
标志放在一起呢?非常感谢您的答案! - Droydn