1

Ok, what we have:

Program written on C which compiling and running without problems in Linux and MacOSX (leopard). I embedded lua code today. Linux: compiled lua 5.1 from source. Everything works and compiles without any problems. Macos: compiled the same lua 5.1 package.

Linked with --llua.

Started compile and got an error:

CC=gcc-4.0 make

ld: warning: in /usr/local/lib/liblua.a, file is not of required architecture

Also tried reinstall, complete remove and installing from macports. The same.

So is there any fix for that?

  • `_Lua_Call` is not a symbol in the Lua C API. – lhf Apr 16 '12 at 12:21
  • Cool, but its compiling and its working, the main problem with macos error ld: warning: in /usr/local/lib/liblua.a, file is not of required architecture – TotallyStuck Apr 16 '12 at 13:25
  • 2
    If you have compiled and installed Lua from source downloaded from http://www.lua.org this should not happen. – lhf Apr 16 '12 at 13:26
  • Yes and also the same error with Lua from macports – TotallyStuck Apr 16 '12 at 13:44
  • See Luiz's (one of Lua's authors) comment above. Lua's source is pure ANSI C with no external dependencies. It's incredibly easy to build. Rather than lying on a library built by someone else, just build it yourself or add the source to your project. It's beyond trivial on a Unix-like system. – Mud Apr 16 '12 at 16:54
  • Thx, i know that. But tried everything. Whats the normal way to link to lua libraries when building program with gcc? – TotallyStuck Apr 16 '12 at 18:29
  • *For dynamic compile. For static i think its -llua or -llua5.1 depends of what package do you have – TotallyStuck Apr 16 '12 at 18:44

1 Answers1

0

The error "file is not of required architecture" hints to the fact that you're trying to mix architectures.

Check the architecture of the /usr/local/lib/liblua.a and make sure it matches the architecture or the object you're trying to build.

E.g.

We have a i386 object:

==== cat fun.c ==== 
#include <stdio.h>
void fun()
{
    printf("%s", "foobar\n");
}
gcc -arch i386 -c fun.c -o fun.o

if we try to use it when compiling a x86_64 object (default architecture in Mac OS X):

===== cat test.c ==
extern void fun();
int main()
{
    fun();
}

we get:

$ gcc test.c fun.o
ld: warning: ignoring file fun.o, file was built for i386 which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
  "_fun", referenced from:
      _main in ccXVCQhG.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
diciu
  • 29,133
  • 4
  • 51
  • 68
  • I think you are right. But how can i change the arch of liblua.a ? Compile from source?I think I already tried that – TotallyStuck Apr 20 '12 at 16:17
  • 1
    You either recompile liblua.a or recompile your program matching the architecture of liblua.a. – diciu Apr 20 '12 at 16:21
  • Did it. Now i have: Undefined symbols: and ld: symbol(s) not found – TotallyStuck Apr 21 '12 at 10:49
  • So you've solved the architecture mismatch by using i386 both for liblua and your code and you face missing symbol errors. Which are the missing symbols? Are they exported by liblua? **nm /usr/local/lib/liblua.a** will show you the symbols. See the `nm` man page for details. – diciu Apr 23 '12 at 09:40
  • Like lhf said this symbols are not symbols in the Lua C API. But on on my Ubuntu its compiling without problems. – TotallyStuck Apr 23 '12 at 15:18
  • It's likely that somewhere in your source file you have a call to *Lua_Init*. Since there's no such call in the LUA API, you will get an undefined symbol. – diciu Apr 24 '12 at 10:31