|
> try this piece of code which demonstrates the usage of Lua and iuplua from C. this should be copy-paste ready. Thanks! The test code worked fine, assuming all that’s supposed to happen is the popup window appears. > '-llua' asks the linker to look for `liblua.a`; if the file name was `liblua5.1.a`, you need to use `-llua5.1` instead. Changing it to ‘-llua5.1’ helped. I noticed some other ‘-l’ items that weren’t working right when trying to debug the original app. I took them from the Makefile and put them into c_cpp_properties.json. Those were "-lcdluaiup" and "-lcdiup". I don’t have any files called ‘libcdluaiup.a’ or ‘libcdiup.a’ in C:\MyLibs\cd, however in the ‘include’ subfolder, there’s one called cdluaiup.h. C:\MyLibs\iup DOES have a file called ‘libiupcd.a’ and the ‘Lua51’ subfolder has one called ‘libiupluacd51’, so I replaced "-lcdluaiup" and "-lcdiup" with “-liupluacd51” and “-liupcd” in case the file names have been changed over the years, but I still get errors. Trying to debug the app’s C file gives me this: > Executing task: C/C++: gcc.exe build active file < Starting build... C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe -fdiagnostics-color=always -g C:\Users\name\Desktop\Apps\src\citybinder.c -o C:\Users\name\Desktop\Apps\src\citybinder.exe -IC:/MyLibs/lua-5.1/include -IC:/MyLibs/cd/include -IC:/MyLibs/im/include -IC:/MyLibs/iup/include -LC:/MyLibs/lua-5.1 -LC:/MyLibs/cd -LC:/MyLibs/cd/Lua51 -LC:/MyLibs/im -LC:/MyLibs/im/Lua51 -LC:/MyLibs/iup -LC:/MyLibs/iup/Lua51 -lcdlua51 -lcd -lim -liuplua51 -llua5.1 -liup -liupcontrols -liupluacontrols51 -liupluacd51 -liupcd -liupluaim51 -liupim -lpsapi -lgdi32 -luser32 -lkernel32 -lcomctl32 -lcomdlg32 -lole32 -luuid -ladvapi32 -lshell32 -lws2_32 C:\Users\name\Desktop\Apps\src\citybinder.c: In function 'cb_sysexec': C:\Users\name\Desktop\Apps\src\citybinder.c:558:7: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] if ((int)(info.hInstApp) > 32) { ^ C:\Users\name\Desktop\Apps\src\citybinder.c: In function 'main': C:\Users\name\Desktop\Apps\src\citybinder.c:683:3: warning: implicit declaration of function 'IupControlsClose'; did you mean 'IupControlsOpen'? [-Wimplicit-function-declaration] IupControlsClose(); ^~~~~~~~~~~~~~~~ IupControlsOpen C:\Users\name\AppData\Local\Temp\ccQtlwy8.o: In function `main': C:/Users/name/Desktop/Apps/src/citybinder.c:683: undefined reference to `IupControlsClose' C:/MyLibs/cd/libcd.a(cdirgb.o):cdirgb.c:(.text+0x49f3): undefined reference to `FT_Set_Transform' C:/MyLibs/cd/libcd.a(cdirgb.o):cdirgb.c:(.text+0x4a03): undefined reference to `FT_Load_Char' C:/MyLibs/cd/libcd.a(cdirgb.o):cdirgb.c:(.text+0x4bbf): undefined reference to `FT_Load_Char' C:/MyLibs/cd/libcd.a(zip.o):zip.c:(.text+0x1408): undefined reference to `crc32' C:/MyLibs/cd/libcd.a(zip.o):zip.c:(.text+0x151c): undefined reference to `deflate' C:/MyLibs /cd/libcd.a(zip.o):zip.c:(.text+0x19d0): undefined reference to `deflate' C:/MyLibs/cd/libcd.a(zip.o):zip.c:(.text+0x1a59): undefined reference to `deflateEnd' C:/MyLibs/cd/libcd.a(zip.o):zip.c:(.text +0x1b02): undefined reference to `deflateEnd' C:/MyLibs/cd/libcd.a(zip.o):zip.c:(.text+0x1b23): undefined reference to `deflateEnd' C:/MyLibs/cd/libcd.a(zip.o):zip.c:(.text+0x1c34): undefined reference to `deflateEnd ' C:/MyLibs/cd/libcd.a(zip.o):zip.c:(.text+0x24a7): undefined reference to `deflateInit2_' C:/MyLibs/cd/libcd.a(unzip.o):unzip.c:(.text+0x1d52): undefined reference to `crc32' C:/MyLibs/cd/libcd.a(unzip.o):unzip.c:(.text+0x1e48): undefined reference to `inflate' C:/MyLibs/cd/libcd.a(unzip.o):unzip.c:(.text+0x1e84): undefined reference to `crc32' C :/MyLibs/cd/libcd.a(unzip.o):unzip.c:(.text+0x20c9): undefined reference to `inflateEnd' C:/MyLibs/cd/libcd.a(unzip.o):unzip.c:(.text+0x269f): undefined reference to `inflateInit2_' C:/MyLibs /cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0x21): undefined reference to `FT_New_Face' C:/MyLibs/cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0x70): undefined reference to `FT_Set_Char_Size' C:/MyLibs/cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0x8c): undefined reference to `FT_Done_Face' C:/MyLibs/cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0xec): undefined reference to `FT_Set_Charmap' C:/MyLibs/cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0xfb): undefined reference to `FT_Done_Face' C:/MyLibs/cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0x12d): undefined reference to `FT_Init_FreeType' C:/MyLibs/cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0x183): undefined reference to `FT_Library_Version' C:/MyLibs/cd/libcd.a(cd_truetype.o ):cd_truetype.c:(.text+0x210): undefined reference to `FT_Done_Face' C:/MyLibs/cd/libcd.a(cd_truetype.o):cd_truetype.c:(.text+0x218): undefined reference to `FT_Done_FreeType' C:/MyLibs/cd /libcd.a(sim_text.o):sim_text.c:(.text+0x24): undefined reference to `FT_Library_Version' C:/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0x356): undefined reference to `FT_Set_Transform' C :/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0x38d): undefined reference to `FT_Load_Char' C:/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0x3bc): undefined reference to `FT_Load_Char' C:/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0x5ac): undefined reference to `FT_Matrix_Multiply' C:/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0x6cf ): undefined reference to `FT_Matrix_Multiply' C:/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0x7cc): undefined reference to `FT_Set_Transform' C:/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0x7e7): undefined reference to `FT_Load_Char' C:/MyLibs/cd/libcd.a(sim_text.o):sim_text.c:(.text+0xb9c): undefined reference to `FT_Load_Char' C:/MyLibs/cd/libcd.a(cdwprn.o):cdwprn.c:(.text+0x421 ): undefined reference to `__imp_DeviceCapabilitiesW ' collect2.exe: error: ld returned 1 exit status I don’t know if the order of ‘-l’ items is wrong or if I’m missing some things. How do you tell what’s dependent on what? I think adding “-lfreetype6” helped get rid of some errors, but I’d like to know if there’s a specific way of determining what to add. If I try using the Makefile, I get this error still: ld.exe: unrecognised emulation mode: windows Supported emulations: i386pep i386pe From: nerditation On 2021/10/24 5:18, Kaz wrote: > > I made c_cpp_properties.json like you said, but used '"compilerPath": "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe"' because I want to test embedding Lua in C. Since I’m using Lua 5.1, I changed -llua54 to -llua, and -liuplua54 to -liuplua51. Did I need the dynamic link section if I’m not using that? I left that out. > that should be fine, the dynamic configuration and static configuration are independent of each other. > What should I put into the files to test? try this piece of code which demonstrates the usage of Lua and iuplua from C. this should be copy-paste ready. ```C #include <stdio.h> #include <lua.h> #include <lualib.h> #include <lauxlib.h> #include <iup.h> #include <iuplua.h> typedef struct { char const *name; lua_CFunction loaderfn; } Preloader; /* list the Lua modules you want to preload here */ static const Preloader preloaders[] = { { "iuplua", &iuplua_open }, { NULL, NULL }, }; int main(int argc, char const *argv[]) { /* do something in C */ printf("hello C!\n"); /* init Lua runtime */ lua_State *L = luaL_newstate(); luaL_openlibs(L); /* try run some Lua code */ luaL_dostring(L, "print 'hello Lua!'"); /* install preloaders into package.preload */ lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); Preloader const *mod = &preloaders[0]; while (mod->name != NULL) { lua_pushcfunction(L, mod->loaderfn); lua_setfield(L, -2, mod->name); ++mod; } lua_pop(L, 2); /* try run some more Lua code with iup */ luaL_dostring(L, "local iup = require 'iuplua'; iup.Message('hello', 'hello iuplua!');"); lua_close(L); return 0; } ``` > to appease VSCode. The build/debug said it couldn’t find ‘-llua’ this command line must match the file name you extracted from the Lua zip package, '-llua' asks the linker to look for `liblua.a`; if the file name was `liblua5.1.a`, you need to use `-llua5.1` instead. as of the order, the dependencies should listed after the dependents. e.g. iuplua must listed before both lua and iup. if you are not sure, a common trick is to simply repeat the libraries several times in the same order (typically twice would be enough). btw, there are ways to get away from this quirky linker behavior, but I'm afraid you have to investigate more into it yourself. |