请不要把我钉在十字架上。ChatGPT 或 Google 什么都没做,所以我就在这里。基本上,我无法在我的 C++ 代码中使用 QtWidgets(出于某种原因)。
问题:当我在 C++ 中包含标题时,出现此错误:
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 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
到目前为止,代码应该可以渲染一个基本窗口。但事实并非如此。我在 SO 上提问,得到的回答只有反对票和“你的 makefile”。