On Windows in Visual Studio, it was enough to scatter files into special folders and register:

#include <GL/glut.h> #pragma comment (lib, "opengl32.lib") #pragma comment (lib, "glu32.lib") #pragma comment (lib, "glut32.lib") 

How to be on Linux? From this answer I understood that #pragma comment will not work. I also realized that in CMakeLists.txt you need to prescribe all the links yourself. I put freeglut3-dev and what do I link from?
Here is my CMakeLists.txt :

 cmake_minimum_required(VERSION 3.8) project(paintc) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") file(GLOB SOURCES "*.cpp" "*.h") add_executable(paintc ${SOURCES}) 
  • FIND_PACKAGE to help you, apparently. Well, apparently libraries will be called differently (apparently: freeglut3-dev file list ) - vegorov
  • one
    Example (for libexiv2 dynamic library from libexiv2-dev package): find_package(Exiv2) include_directories( ${EXIV2_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} ${EXIV2_LIBRARIES}) - vegorov
  • What special folders? Why pragma? In VS, you need to specify compilation arguments that specify the paths to folders with libraries and the libraries themselves for linking. On Linux as well. - VTT
  • @VTT C: \ Program Files (x86) \ Microsoft Visual Studio \ 2017 \ Professional \ VC \ Tools \ MSVC \ 14.11.25503, in it bin, lib and include. Here are these special folders. And in VS, they are specified by default, so you don’t need to add anything. What do you do on Linux? - Puro
  • @Eevee I wrote to you. Find (using FIND_PACKAGE) the required package, and register the found header files and libraries - vegorov 2:13 pm

1 answer 1

Everything turned out to be much more interesting. It turns out that when compiling on gcc you need to pass parameters (not files) that point to links. In CMake, this is target_link_libraries(<имя ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°> <ΠΈΠΌΠ΅Π½Π° Π²ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½Π½Ρ‹Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌΠΈ ΠΈ Π±Π΅Π· Π±ΡƒΠΊΠ²Ρ‹ l Π²Π½Π°Ρ‡Π°Π»Π΅>) using target_link_libraries(<имя ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°> <ΠΈΠΌΠ΅Π½Π° Π²ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½Π½Ρ‹Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌΠΈ ΠΈ Π±Π΅Π· Π±ΡƒΠΊΠ²Ρ‹ l Π²Π½Π°Ρ‡Π°Π»Π΅>) . In my case it will look like this: target_link_libraries(paintc glut GLU GL) . When calling gcc , you will need to specify -lglut -lGLU -lGL .

  • if anything, then you will almost certainly link dynamic libraries, not static ones ... - Fat-Zer 8:56 pm.
  • @ Fat-Zer OK, I'll take note. Thank. - Puro
  • Why call gcc pointing flags again? CMake generates a Makefile in which everything is already configured. This is the meaning of the assembly system. In addition, target_link_libraries takes different parameters - cpp questions
  • Yes, no one calls gcc . I dragged him for example, if someone will google the same problem. And what about the target_link_libraries parameters, it all worked for me with such parameters. - Puro
  • one
    target_link_libraries(<имя ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°> <ΠΈΠΌΠ΅Π½Π° Π²ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ Ρ€Π°Π·Π΄Π΅Π»Π΅Π½Π½Ρ‹Π΅ ΠΏΡ€ΠΎΠ±Π΅Π»Π°ΠΌΠΈ ΠΈ Π±Π΅Π· Π±ΡƒΠΊΠ²Ρ‹ l Π²Π½Π°Ρ‡Π°Π»Π΅>) is not the name of the project, but the name of the executable file or library (target) that you create using add_executable or add_library . And if you specified ${PROJECT_NAME} as the first parameter of add_executable or add_library , then yes, then the name of the project is vegorov