c++ # include< QtWidgets>:没有这样的文件或目录

h9a6wy2h  于 2024-01-09  发布在  其他
关注(0)|答案(1)|浏览(219)

请不要把我钉死在十字架上。ChatGPT或Google什么也没做,所以我在这里。基本上,我不能在我的C++代码中使用QtWidgets(出于某种原因)。

**问题:**当我在C++中包含<QtWidgets>头时,我得到这个错误:

  1. g++ -std=c++11 -Wall -Wextra -Isrc -Isrc/lib -c src/ui/mainwindow.cpp -o bin/ui/mainwindow.o
  2. src/ui/mainwindow.cpp:3:10: fatal error: QtWidgets: No such file or directory
  3. 3 | #include <QtWidgets> //! doesn't work yet
  4. | ^~~~~~~~~~~
  5. compilation terminated.
  6. make: *** [Makefile:34: bin/ui/mainwindow.o] Error 1

字符串
我试着从Debian仓库重新安装qtbase5-dev软件包。我试着用谷歌搜索并询问ChatGPT。我修改了Makefile如下:

  1. # Makefile for Comet code editor
  2. # Compiler
  3. CC := g++
  4. # Compiler flags
  5. CFLAGS := -std=c++11 -Wall -Wextra
  6. CXXFLAGS += -I/usr/include/qt5
  7. # Include directories
  8. INCLUDE := -Isrc -Isrc/lib # Adjust include paths based on your project structure
  9. # Directories
  10. SRCDIR := src
  11. BUILDDIR := bin
  12. BINDIR := bin
  13. # Source files
  14. SOURCES = src/main.cpp src/ui/mainwindow.cpp src/ui/mainwindow.hpp src/ui/mainwindow.css
  15. # Object files
  16. OBJECTS := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
  17. # Target executable
  18. TARGET := $(BINDIR)/comet
  19. # Default target
  20. all: $(TARGET)
  21. # Linking
  22. $(TARGET): $(OBJECTS)
  23. @mkdir -p $(BINDIR)
  24. $(CC) $(OBJECTS) -o $(TARGET)
  25. # Compiling source files
  26. $(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
  27. @mkdir -p $(BUILDDIR)
  28. $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
  29. # Run the comet executable
  30. run: $(TARGET)
  31. ./$(TARGET)
  32. # Cleaning
  33. clean:
  34. rm -r $(BUILDDIR)
  35. # Phony targets
  36. .PHONY: all run clean


到目前为止,代码应该呈现一个基本的窗口,但它没有。

avwztpqn

avwztpqn1#

你在Makefile中同时使用了CFLAGSCXXFLAGS。为什么?一个就足够了。当然,你应该使用CXXFLAGS,因为你使用的是C编译器(在你的例子中是g)。
问题是你在 * 编译源文件 * 的配方中没有使用CXXFLAGS。该变量包含Qt头文件的包含目录的路径。

相关问题