Cmake i -lm nie kompiluje się

0

Cześć, nie mogę skompilować tego kodu przy użyciu cmake, jak dodać do niego -lm?

#include <math.h>
#include <stdio.h>

int main() {
  int side;
  printf("Enter the value of side: ");
  scanf("%d", &side);

  printf("The value of area is %d", pow(side, 2));
}
undefined reference to `pow'
collect2: error: ld returned 1 exit status

Tak działa

gcc -o test main.c -lm
1

A podasz CMakeLists.txt?

0

CMakeLists.txt jest podstawowy.

cmake_minimum_required(VERSION 3.27.7)
project(Tutorial VERSION 0.1.0 LANGUAGES C CXX)

include(CTest)
enable_testing()

add_executable(Tutorial main.c)


set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED On)
set(CMAKE_C_EXTENSIONS Off)
6

Dorzuć target_link_libraries(Tutorial m) po add_executable.

0

Dziękuję, działa!

1 użytkowników online, w tym zalogowanych: 0, gości: 1