# how to perform a gcc command by using CMake and make

**URL:** https://discourse.cmake.org/t/how-to-perform-a-gcc-command-by-using-cmake-and-make/963
**Category:** Code
**Tags:** os:linux, gen:makefiles
**Created:** [April 9, 2020, 2:44pm UTC](https://discourse.cmake.org/t/how-to-perform-a-gcc-command-by-using-cmake-and-make/963 "2020-04-09T14:44:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Lerner](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@Lerner](https://discourse.cmake.org/u/Lerner)
#### Post date: [April 9, 2020, 2:44pm UTC](https://discourse.cmake.org/t/how-to-perform-a-gcc-command-by-using-cmake-and-make/963/1 "2020-04-09T14:44:32Z")

</div>

Hello everyone, I’m trying to create a statically linked lib-curl executable using CMake but I get undefined reference errors when I try to ‘make’ it, although I can successfully compile it with:  
"gcc -static main.c -o curl-try -pthread -lcurl `curl-config --static-libs`"

my file tree:  
proj/build -\> empty  
proj/main.c  
proj/CMakeLists.txt

The CMakelists.txt file:  
cmake\_minimum\_required(VERSION 3.9)  
project(try\_curl)  
set(BUILD\_SHARED\_LIBS OFF)  
set(CMAKE\_EXE\_LINKER\_FLAGS -static)  
set(CURL\_LIBRARY “-lcurl”)  
find\_package(CURL REQUIRED COMPONENTS libcurl curl-config)  
include\_directories(${libcurl\_INCLUDE\_DIR})  
add\_executable(curl-try main.c)  
target\_link\_libraries(curl-try ${CURL\_LIBRARIES} )

I’ve some questions could you please answer me;

1-So, what would be the correct CMakelists.txt file without exceeding CMake’ s standart Way ?

2-Which variables should I set to let CMake create the correct makefile?

3-How do I call curl-config executable correctly to get static-libs to link main.c file.

4-When I add `curl-config --static-libs` to CMAKE\_EXE\_LINKER\_FLAGS it says curl-config not found but I can successfully call curl config from terminal why it is so ? and how can I overcome that

Thank you, I’m so happy to know that there is such Forum like that.  
I’m looking forward to your answers.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 9, 2020, 8:50pm UTC](https://discourse.cmake.org/t/how-to-perform-a-gcc-command-by-using-cmake-and-make/963/2 "2020-11-09T20:50:40Z")

</div>

You should use `find_package(CURL)` and then you’d just need:

```cmake
find_package(CURL REQUIRED)
target_link_libraries(curl-try CURL::libcurl)

```
