tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] dllimport undefined symbol


From: Jérôme VUARAND
Subject: [Tinycc-devel] dllimport undefined symbol
Date: Wed, 19 Apr 2006 21:06:17 -0400

Hi list,

I'm using lua-tcc, which is a lua binding for tcclib, and I have a
problem with relocation. When using libc functions, relocation is ok
and execution works from inside lua. But when I'm linking to a dll
import library generated with gcc, I have an unresolved symbol error
when I try to relocate the code.

Sorry for the length, but as I have no idea of what can go wrong I
give the maximum detail I can. I tried everything that came to my
mind, but I have no experience with code relocation so the solution to
my problem is probably trivial.

To be clear here is what I have (everything compiled with mingw gcc 3.2.3) :
- tcc-0.9.23 :
  -> libtcc.a
- a custom lib-tcc (I've modified it to be able to specify include
path from lua) compiled in a dll :
  -> lua_tcc.dll (the dll containing lib-tcc linked to libtcc.a)
  -> liblua_tcc.a (the import library of lua_tcc.dll)
- a slightly patched lua-5.1 compiled in two dll :
  -> lua.dll (+ liblua.a import lib)
  -> lualib.dll (+ liblualib.dll import lib)
  -> lua.exe

I'm then doing the following :
A. I load liblua_tcc.dll
B. I create a tcc_state
C. I add include and lib pathes to both tcc and lua
D. I compile the following source :
#include <lua.h>

int foo(lua_State* L) {
        char const* str = lua_tolstring(L, 1, 0);
        printf("Hello World!\n");
        printf("- 0x%s\n", str);
        return 1;
}
E. I add the libraries "lua" and "lualib"
F. I relocate the code

And at that moment I have the following error :
<string>:9: undefined symbol 'lua_tolstring'

That function is declared in lua.h as :
__declspec(dllimport) const char *(lua_tolstring) (lua_State *L, int
idx, size_t *len);

It is in lua.dll as "lua_tolstring" (no prefixed underscore or @
parameter size).

It is in liblua.a import library as follows (output from "nm liblua.a
| grep lua_tolstring") :
00000000 I __imp__lua_tolstring
00000000 T _lua_tolstring

Both lua.dll and liblua.a code is already loaded in the process when
relocating, I don't know if that can cause a problem.

I have found absolutely no documentation on how to link with a dll
with tcc on windows, so I don't even know if using gcc import
libraries should work.

Does anyone have an idea of what my problem is ?
Is libtcc able to link the code it compiles to code already loaded in
the process (it seems to me much more complex than what get_symbol
does, so maybe it can't) ? Is tcc supporting import libraries for dlls
as gcc does ? Is the __declspec(dllimport) declaration valid and
understood or is it ignored by tcc ?

I hope the answer to my problems is not "you can't do it (yet)".
Thanks in advance.

Doub.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]