LinuxUseStaticHow to use the linkLuaIs the content to be introduced in this article, mainly to learnLinuxUsed inLuaFor more information, see the detailed description of this article.
The environment is ubuntu9.04.
First, go to the lua official website to download the latest version of lua.
After decompression, enter the directory from the shell and execute make
You will be prompted to select the make version.
Make linux
Then start building. Wait and enter the src directory, which contains liblua..
Copy to the directory required by the project.
At the same time, we need to copy the. h file. I suggest copying all the header files to the/usr/include file for later use. Otherwise, we need to add the command line in gcc each time.
To specify a header file in gcc, see:
- http://blog.chinaunix.net/u/28781/showart.php?id=401631
Then you can compile the code. My test code is:
Code
- void load (char *filename, int *width, int *height) {
-
- lua_State *L = lua_open();
- luaopen_base(L);
- luaopen_io(L);
- luaopen_string(L);
- luaopen_math(L);
- if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0))
- error(L, "cannot run configuration file: %s",
- lua_tostring(L, -1));
- lua_getglobal(L, "width");
- lua_getglobal(L, "height");
- if (!lua_isnumber(L, -2))
- error(L, "`width' should be a number\n");
- if (!lua_isnumber(L, -1))
- error(L, "`height' should be a number\n");
- *width = (int)lua_tonumber(L, -2);
- *height = (int)lua_tonumber(L, -1);
- lua_close(L);
- }
- int main()
- {
- return 0;
- }
The compiled command line is:
- gcc test.c -L$HOME/Code/luatest -llua -lm
Note that gcc does not needStaticAdd lib to the front of the library to obtain liblua .. At the beginning of compilation, I always asked why I couldn't find it. Then I asked Daniel in the group to solve the problem.
-Lm is also required, because lua needs to use the libm library.
Summary:LinuxUseStaticHow to use the linkLuaI hope this article will help you!