g++编译Qt Widgets程序时提示<QtWidgets>头文件不存在的问题求助
g++编译Qt Widgets程序时提示头文件不存在的问题求助
各位大佬求帮忙!我现在在写C++程序想用QtWidgets,但死活搞不定头文件的问题,ChatGPT和谷歌搜了一圈都没解决办法,只能来这儿求助了(轻喷轻喷🙏)
问题详情
我在代码里引入<QtWidgets>头文件后,编译直接报错,错误信息如下:
g++ -std=c++11 -Wall -Wextra -Isrc -Isrc/lib -c src/ui/mainwindow.cpp -o bin/ui/mainwindow.o src/ui/mainwindow.cpp:3:10: fatal error: QtWidgets: No such file or directory 3 | #include <QtWidgets> //! doesn't work yet | ^~~~~~~~~~~ compilation terminated. make: *** [Makefile:34: bin/ui/mainwindow.o] Error 1
我已经尝试过的操作
- 重新安装了Debian仓库里的
qtbase5-dev包 - 谷歌搜了相关错误,也问过ChatGPT,给出的方案都不生效
- 修改了项目的Makefile,调整了包含路径,修改后的Makefile内容如下:
# Makefile for Comet code editor # Compiler CC := g++ # Compiler flags CXXFLAGS := -std=c++11 -Wall -Wextra -I/usr/include/qt5 # Include directories # INCLUDE := -Isrc -Isrc/lib # Adjust include paths based on your project structure # Directories SRCDIR := src BUILDDIR := bin BINDIR := bin # Source files SOURCES = src/main.cpp src/ui/mainwindow.cpp src/ui/mainwindow.hpp src/ui/mainwindow.css # Object files OBJECTS := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES)) # Target executable TARGET := $(BINDIR)/comet # Default target all: $(TARGET) # Linking $(TARGET): $(OBJECTS) @mkdir -p $(BINDIR) $(CC) $(OBJECTS) -o $(TARGET) # Compiling source files $(BUILDDIR)/%.o: $(SRCDIR)/%.cpp @mkdir -p $(BUILDDIR) $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ # Run the comet executable run: $(TARGET) ./$(TARGET) # Cleaning clean: rm -r $(BUILDDIR) # Phony targets .PHONY: all run clean
目前我的代码只是想渲染一个最基础的Qt窗口,但现在连编译这关都过不了。之前我在Stack Overflow提问过,结果只得到一堆踩,还有人模糊地说“你的Makefile有问题”,但没说具体哪里有问题,实在没办法了才再来求助!
备注:内容来源于stack exchange,提问作者Renegade
相关产品推荐
相关产品推荐

