Summary: CMake runs correctly from the command line, but can’t find library files installed with homebrew when run from VSCode.
Here are my includes that are giving trouble:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
Here is my CMakeLists.txt. In lines 4, 5, and 6, you can see my various efforts to get it to find FLTK.
cmake_minimum_required(VERSION 3.5)
project(HelloFLTK)
set(CMAKE_PREFIX_PATH "/opt/homebrew")
find_package(FLTK REQUIRED)
include_directories(${FLTK_INCLUDE_DIRS} /opt/homebrew/opt/fltk/include)
link_directories(${FLTK_LIBRARY_DIRS})
add_executable(HelloFLTK main.cpp)
target_link_libraries(HelloFLTK ${FLTK_LIBRARIES})
When run from the command line:
% cmake --build .
[ 50%] Building CXX object CMakeFiles/HelloFLTK.dir/main.cpp.o
[100%] Linking CXX executable HelloFLTK
[100%] Built target HelloFLTK
Here is my tasks.json. Looks like it’s invoking CMake, right?
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cmake",
"args": ["-DCMAKE_BUILD_TYPE=Debug", "${workspaceFolder}"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Results of running with Command-shift-B. Inadequate command line generated. But I can confirm that Command-shift-B is bound to “Tasks: Run Build Task”
* Executing task: C/C++: g++ build active file
Starting build...
/usr/bin/g++ -fdiagnostics-color=always -g /Users/ken/vsc/fl/main.cpp -o /Users/ken/vsc/fl/main
/Users/ken/vsc/fl/main.cpp:1:10: fatal error: 'FL/Fl.H' file not found
#include <FL/Fl.H>
^~~~~~~~~
1 error generated.
Build finished with error(s).
% ls /opt/homebrew/opt/fltk/include/FL
Enumerations.H Fl_JPEG_Image.H Fl_Table_Row.H
Fl.H Fl_Light_Button.H Fl_Tabs.H
Fl_Adjuster.H Fl_Line_Dial.H Fl_Text_Buffer.H
. . . and many, many more.
So what is creating a different situation in Visual Studio code, and how do I help it find these include files?
The whole source file, for reproduceability:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char *argv[]) {
Fl_Window *window = new Fl_Window(300, 180);
Fl_Box *box = new Fl_Box(20, 40, 260, 100, "Hello, dear World!");
box->box(FL_UP_BOX);
box->labelfont(FL_BOLD + FL_ITALIC);
box->labelsize(36);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}