You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 13:17:58