12/1/2023 0 Comments Cmake visual studio run![]() Moreover, their locations are known to the GCC tools. On Ubuntu, we can install this library with apt: $ sudo apt install libcurl4-nss-devĪfterwards, we should be provided with both curl header files and shared libraries. Next, we’ll use the curl development library in our program. ![]() Let’s assume we’re using the GCC compiler in Linux and Visual Studio in Windows. Since Linux and Windows manage libraries differently, we can handle it with CMake. When creating an executable from the C source code, we often need to provide third-party libraries. Now, we’ll write the corresponding C program, ostest.c: Then, a series of target_compile_definitions commands sets appropriate variables. So, Windows stands for Visual Studio or MinGW GCC under the Windows system. Notably, they describe both the system and the compiler. We rely on the CMake internal code names for platforms, such as Linux, Darwin, or Windows. Target_compile_definitions(ostest PUBLIC "WINDOWS_OS") Target_compile_definitions(ostest PUBLIC "MACOS_OS") ![]() Target_compile_definitions(ostest PUBLIC "LINUX_OS") # set variable for the C preprocessor to detect the operatong system To achieve it, we’re going to use CMake’s internal variable CMAKE_SYSTEM_NAME: # CMakeLists file As a result, the instructions for the specific operating system will be compiled. Then the C preprocessor can check if the variable is set, and conditionally arrange the code. For example, under Linux, we’re going to define the variable LINUX_OS, in Windows its name is WINDOW_OS, and so on. So, let’s write a CMakeLists.txt file that defines different variables for each operating system. CMake has the ability to detect the operating system. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |