0

This is my C code:

#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
int main(void)
{
    lua_State *L = luaL_newstate();
    luaL_openlibs(L);
    luaL_dofile(L, "/home/test/test.lua");
    lua_close(L);
    return 0;
}

The code is compiled with the command:

sudo gcc /home/test/src/main.c -llua -ldl -lm -o /home/test/test.o

All right and is working. But if I use the CMakeLists.text, compile fails!

CMakeLists.txt :

cmake_minimum_required(VERSION 2.8)
project(testc C)

set(CMAKE_SHARED_LINKER_FLAGS  "${CMAKE_C_FLAGS} -llua -ldl -lm")

file(GLOB headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.h)

add_executable(testc src/main.c)
target_link_libraries(testc ${LUA_LIBRARIES})
install(TARGETS testc DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})

Error:

[ 50%] Building C object CMakeFiles/testc.dir/src/main.c.o
[100%] Linking C executable testc
CMakeFiles/testc.dir/src/main.c.o: In function `main':
main.c:(.text+0x9): undefined reference to `luaL_newstate'
main.c:(.text+0x19): undefined reference to `luaL_openlibs'
main.c:(.text+0x2f): undefined reference to `luaL_loadfilex'
main.c:(.text+0x5a): undefined reference to `lua_pcallk'
main.c:(.text+0x6b): undefined reference to `lua_close'

why??

Thank you.

A.B
  • 41
  • 3
  • 4

0 Answers0