CLion IDE (CMake): Project builds but no intelligence for external libraries - c++

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
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)

For anyone encountering this issue call Tools | Resync with Remote Hosts -

Related

Configure SFML On CLion For VS Compiler

I downloaded SFML using vcpkg, and I wanted to use SFML in CLion. So, in the CMake options I put:
-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake
for using vcpkg modules.
My CMakeList.txt is:
cmake_minimum_required(VERSION 3.7)
project(Test)
set(CMAKE_CXX_STANDARD 20)
FIND_PACKAGE(SFML REQUIRED system window graphics network audio)
INCLUDE_DIRECTORIES(${SFML_INCLUDE_DIR})
add_executable(Test main.cpp)
TARGET_LINK_LIBRARIES(Test ${SFML_LIBRARIES} ${SFML_DEPENDENC})
CMake shows:
Found SFML 2.5.1 in C:/vcpkg/installed/x86-windows/share/sfml
But CLion tells me that SFML/Audio.hpp was not found.
Is there something wrong with my CMakeList?
How can I configure SFML in CLion?

Hooking up CLion with Qt

I want to be able to run my Qt applications from CLion. In order to do so, I'm using MinGW, CLion, and Qt 5.15.0. In Settings > Build, Execution, Deployment > CMake, I've set my CMake Options as the following:
-DCMAKE_PREFIX_PATH=/Qt/5.15.0/mingw81_64/lib/cmake
In Settings > Build, Execution, Deployment > Toolchains, I've set my Environment as the following:
C:\Qt\Tools\mingw810_64
The C and C++ compilers have been automatically detected so I'm not too worried about that. For the file main.cpp, I have the following:
#include <QApplication>
#include <QDebug>
int main() {
qDebug() << QT_VERSION_STR;
return 0;
}
For CMakeLists.txt, I have the following:
cmake_minimum_required(VERSION 3.3)
project(Practice)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
find_package(Qt5Widgets REQUIRED)
add_executable(Practice ${SOURCE_FILES})
target_link_libraries(Practice Qt5::Widgets)
Building this test project gives me no warnings or errors but running it does. Why is this? Here's the error code I get when it does run.
C:\Users\IvanJaramillo\CLionProjects\Practice\cmake-build-debug\Practice.exe
Process finished with exit code -1073741511 (0xC0000139)
Changing compilers from MinGW to Cygwin and changing the versions of it hasn't done the job.

Index Qt5 in Eclipse IDE project using Cmake

Background
I'm currently using Eclipse Neon.3 and have installed the "C/C++ CMake Build Support - Experimental" package (I'm not using CMake's Eclipse generator). I have a simple program that uses Qt 5.8 which builds successfully, however, Eclipse seems unable to index Qt symbols(e.g. QCoreApplication, QDebug, etc...).
The symptoms of this are:
No code completion suggestions
#include <QtCore> and other include statements are shown as unresolved
Qt symbols such as QCoreApplication, QDebug(), and QCoreApplication.exec() are shown as not resolved.
Code
CMakeLists.txt file
cmake_minimum_required(VERSION 3.5)
project(test-program)
set(CMAKE_CXX_STANDARD 11)
# Put the CMake files for Qt5 in the Prefix path.
set(Qt5_DIR /opt/Qt/5.8/gcc_64/lib/cmake/Qt5/)
#Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
#Find the Qt5Core Library
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
set(SOURCE_FILES
src/main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
main.cpp (shown with eclipse annotations)
#include <QtCore> //Unresolved inclusion: <QtCore>
#include <QDebug> //Unresolved inclusion: <QDebug>
int main(int argc, char** argv){
QCoreApplication application(argc, argv);
//Type 'QCoreApplication' could not be resolved
qDebug() << "Test";
//Function 'qDebug' could not be resolved
application.exec();
//Method 'exec' could not be resolved
return 0;
}
Question
So my question is this: How can I get Eclipse to recognize Eclipse to recognize Qt symbols? Or is that just not possible at this time?
Did you enable the "CDT GCC Build Output Parser"? This is an Eclipse feature to parse the output of the build and guesses the include paths automatically. You can find it unter Project Properties->C/C++ General->Preprocessor Include Paths, Macros etc. and then under the tab Providers.
In order for this feature to work properly, a detailed build report must be generated. You can achieve this by either changing the build command under Preferences->C/C++ Build to make VERBOSE=1 or by specifying set(CMAKE_VERBOSE_MAKEFILE On) inside your CMakeLists.txt.
See also Eclipse Help - Scanner Discovery Preferences

Getting SDL2 to work on Clion, Windows 10 using MinGW

I cannot for the life of me get SDL2 to work with my programming group's project.
I'm using
-Clion 1.2.1
-SDL 2.0.3
-MinGW 5.0
The compiler starts yelling at me from within the Graphics.h file which includes SDL like so:
#include <SDL.h>
#include <SDL_image.h>
with the error being:
fatal error: SDL.h: No such file or directory
compilation terminated.
I tried including with
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
which still yielded the same error.
I downloaded SDL from the MinGW 32/64-bit download of development libraries from: https://www.libsdl.org/download-2.0.php. I also linked the respective ..\SDL2\x86_64-w64-mingw32\include and lib to path in system->advanced system settings->...
Still nothing.
cmake_minimum_required(VERSION 3.3)
project(ClionProjects)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lsdl2")
set(SOURCE_FILES
Kod/Graphics/Graphics.cc
Kod/Graphics/Graphics.h
Kod/Game/Game.cc
Kod/Game/Game.h
Kod/Gameboard/Gameboard.cc
Kod/Gameboard/Gameboard.h
Kod/Meeple/Meeple.cc
Kod/Meeple/Meeple.h
Kod/Player/Player.cc
Kod/Player/Player.h
Kod/Resource/Resource.cc
Kod/Resource/Resource.h
Kod/Tile/Tile.cc
Kod/Tile/Tile.h
Kod/Carcassonne.cc)
add_executable(ClionProjects ${SOURCE_FILES} Kod/Carcassonne.cc)
target_link_libraries(ClionProjects SDL2main SDL2 SDL2_image)
is the cmakefile I have in Clion. I've been bashing my head bloody trying to get this to work and none of the previous Stackoverflow questions managed to solve my issue.
Personally I uses MSYS2 in my project. The MINGW64 vesion of SDL2 and the other library were installed, as well as the other toolchains like gcc, cmake, and pkg-config (toolchains are MINGW64 version as well).
Then I point my CLion toolchain configuration to the c:\msys2\mingw64, given that I install the msys2 at c:\msys2.
The FindPkgConfig CMake module is used to locate the SDL2 library and include files location.
Please find the example below (I also use FreeType2 and harfbuzz as well). The important part is the FindPkgConfig part (pkg_check_modules) and include/link part.
Make sure to reload the configuration after you have modified the cmake file.
cmake_minimum_required (VERSION 2.6)
project (pgengine)
# The version number.
set (Tutorial_VERSION_MAJOR 0)
set (Tutorial_VERSION_MINOR 1)
add_definitions(-std=c++11)
aux_source_directory(src SRC_LIST)
aux_source_directory(src/game SRC_LIST)
aux_source_directory(src/graphics SRC_LIST)
aux_source_directory(src/sound SRC_LIST)
aux_source_directory(src/system SRC_LIST)
aux_source_directory(src/visual_novel SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
INCLUDE(FindPkgConfig)
pkg_check_modules(FREETYPE2 REQUIRED freetype2)
pkg_check_modules(HARFBUZZ REQUIRED harfbuzz)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL2_MIXER REQUIRED SDL2_mixer)
include_directories(${SDL2_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
${FREETYPE2_INCLUDE_DIRS}
${HARFBUZZ_INCLUDE_DIRS})
link_directories (${SDL2_LIBRARY_DIRS}
${SDL2_IMAGE_LIBRARY_DIRS}
${SDL2_MIXER_LIBRARY_DIRS}
${FREETYPE2_LIBRARY_DIRS}
${HARFBUZZ_LIBRARY_DIRS})
target_link_libraries (pgengine ${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${FREETYPE2_LIBRARIES}
${HARFBUZZ_LIBRARIES})
This has been tested on Windows (MSYS2) and Linux.

SFML not found - CLion/Cmake

I'm basically trying to make an SFML project in CLion which uses CMake.
I first downloaded SFML 2.2 which already had the .dylib files built. It said to install them in usr/local/lib and usr/local/include, but they didn't exist, so I created them and then put the files there.
I then opened up CLion, created a subdirectoy cmake_modules, placed the FindSFML.cmake file inside, and in the root project directory placed these files:
main.cpp
#include <SFML/Graphics.hpp>
int main()
{
sf::err() << "Hello, World!" << std::endl;
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(HelloWorld)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(HelloWorld ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML COMPONENTS graphics window system REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(HelloWorld ${SFML_Libraries})
The problem is that when I try to build the project, I get the following error:
Undefined symbols for architecture x86_64:
"sf::err()", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've tried searching for a solution, but none of them seem to be working. Did I put the files in the wrong place, or did I forget some import CMake setting? I know that setting SFML up with Xcode would be easier, but I'd prefer to use CLion if at all possible.
Ok, so I made an entirely new project, ran xcode-select --install on my terminal to make /usr/local/ a directory that gets searched by the compiler, downloaded SFML 2.3 instead of 2.2, decided to use the FindSFML.cmake file shipped with SFML, and made my CmakeLists.txt file look like so:
cmake_minimum_required(VERSION 3.2)
project(SFMLTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(SFMLTest ${SOURCE_FILES})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "~/SFML-2.3/cmake/Modules/")
find_package(SFML REQUIRED graphics window system)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(SFMLTest ${SFML_LIBRARIES})
endif(SFML_FOUND)
This compiled and ran the following code in CLion:
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "Window");
while (window.isOpen())
{
sf::Event e;
while (window.pollEvent(e))
{
if (e.type == sf::Event::Closed)
{
window.close();
}
}
window.clear();
window.display();
}
return 0;
}
I don't know what exactly fixed everything, but I'm just glad it did. Hopefully this helps anyone else who's in a similar jam.
For SFML 2.5 and greater a more modern approach has been taken and setting up cmake is easier.
Example CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(SFMLTest)
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(SFMLTest main.cpp)
target_link_libraries(SFMLTest sfml-graphics sfml-audio)
Note :
Its no longer needed to setup FindSFML.cmake or SFML_ROOT etc.
SFML_LIBRARIES, SFML_DEPENDENCIES and SFML_INCLUDE_DIR don't exist
anymore
More info https://en.sfml-dev.org/forums/index.php?topic=24070.0
For others who downloaded SFML via brew, I managed to fix this by adding this to my CMakeLists.txt
set(SFML_ROOT /usr/local/lib)