CLion IDE (CMake): Project builds but no intelligence for external libraries (GLFW)

Answered

I've implemented the GLFW basic example.

The GLFW header file is reported as not being found and such the CLion IDE is reporting and error and not providing intellisense however the project correctly compiles and runs.

I've added the GLFW library as per the guidance in their documentation (See CMakeLists.txt).

The project is being built and run remotely on Ubuntu 20.04.

 

main.cpp

#include <GLFW/glfw3.h>

int main(void)
{
GLFWwindow* window;

/* Initialize the library */
if (!glfwInit())
return -1;

...
}


CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(untitled1)

set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)


find_package(glfw3 3.3 REQUIRED)

add_executable(untitled1 ${SOURCE_FILES})
target_link_libraries(untitled1 glfw)
1
3 comments

I've just tested with a GTK example and getting the exact same results. Builds and runs fine but no intellisense and reporting "'gtk/gtk.h' file not found".

main.cpp

#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;

window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_widget_show_all (window);
}

int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;

app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);

return status;
}

 

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(untitled1)

set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)


#find_package(glfw3 3.3 REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})

PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)

# Setup CMake to use GTK+, tell the compiler where to look for headers
# and to the linker where to look for libraries
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})

# Add other flags to the compiler
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})


add_executable(untitled1 ${SOURCE_FILES})
target_link_libraries(untitled1 ${GLFW_STATIC_LIBRARIES} ${GTK3_LIBRARIES})
0

Hello!

If you use the full remote mode, please try calling Tools | Resync with Remote Hosts - https://www.jetbrains.com/help/clion/remote-projects-support.html#resync. 

1

Thanks Anna, that has resolved the issue!

0

Please sign in to leave a comment.