Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

undefined reference to `adainit'

504 views
Skip to first unread message

news.broadpark.no

unread,
Feb 16, 2008, 5:39:28 PM2/16/08
to
I must admit that I'm not very experienced with Ada. I'm working with an
interface since I need to be able to call a library written in Ada from
.NET. I made a small project and compiled it as follows:

gnatmake -c api
gnatbind -n api
gnatdll -d api.dll api.ali

Now, everything works fine. I'm able to call the library from a C# .NET
program. However, if I create a GPS project file an try to compile, I get
the following error:

i:\temp\adatest\adadll\obj\api.o:api.adb:(.text+0x38): undefined reference
to `adainit'
i:\temp\adatest\adadll\obj\api.o:api.adb:(.text+0x57): undefined reference
to `adafinal'
gnatmake: gcc execution error

Does anyone know what to do? The GPS project file look like this:

project Api is

for Library_Name use "api";
for Library_Dir use "dll";
for Library_Ali_Dir use "ali";
for Library_Kind use "dynamic";
for Languages use ("Ada");
for Object_Dir use "obj";
for Library_Interface use ("API");
for Library_Auto_Init use "False";
for Library_Src_Dir use "dll";

package Compiler is
for Default_Switches ("Ada") use ("-gnat95", "-gnatv", "-lgnat");
end Compiler;

package Linker is
for Linker_Options use ("-lgnat");
end Linker;

end Api;

Simon Wright

unread,
Feb 17, 2008, 12:51:30 PM2/17/08
to
Are you trying to make a GNAT project file to (re)build the library,
or to use the already-built library? The one you post looks like the
former.

I suspect your problem is the 'for Library_Auto_Init use
"False";'. Why is this here?

news.broadpark.no

unread,
Feb 17, 2008, 2:07:11 PM2/17/08
to
"Simon Wright" <simon.j...@mac.com> wrote in message
news:m24pc75...@mac.com...

I have a library with full source code that I will recompile. However, In
the example I provided I have written a small DLL that I'm compiling.
Compiling it thsi way works:

gnatmake -c api
gnatbind -n api
gnatdll -d api.dll api.ali

However, using GPS with the settings I provided does not work. Making the
project gives the following output:

gnatmake -PI:\Temp\ADATest\AdaDLL\api.gpr -d
gnatbind -n -o b~api.adb -Lapi -a api.ali
gcc -c b~api.adb

building dynamic library for project api
C:\GNAT\2007\bin\gcc.exe -shared -o
i:\temp\adatest\adadll\dll\api.dll -LC:/GNAT/2007/lib/gcc/pentium-mingw32msv/4.1.3/adalib/

i:\temp\adatest\adadll\obj\api.o

... -L.\ -Li:\temp\adatest\adadll\obj\ -LC:/GNAT/2007/lib/gcc/pentium-mingw32msv/4.1.3/adalib/
-Wl,--stack=0x2000000 -LC:/GNAT/2007/lib/gcc/pentium-mingw32msv/4.1.3/adalib/
-lgnat-2007


i:\temp\adatest\adadll\obj\api.o:api.adb:(.text+0x38): undefined reference
to `adainit'
i:\temp\adatest\adadll\obj\api.o:api.adb:(.text+0x57): undefined reference
to `adafinal'

collect2: ld returned 1 exit status
gnatmake: gcc execution error

process exited with status 4

I have problems seeing whats wrong. I have treid different settings for
Library_Auto_Init, but with the same result.

Eirik

Simon Wright

unread,
Feb 17, 2008, 5:12:35 PM2/17/08
to
"news.broadpark.no" <etje...@broadpark.no> writes:

I'm having trouble with Windows, but the Mac OS X .dylib I'm working
on does this:

gcc -c b~tash.adb -fPIC -O2 -fPIC -g -g

building dynamic library for project build_tash_library
/opt/gnat-gpl-2007-static/bin/gcc -dynamiclib -o /Users/simon/sf/tcladashell/lib/libtash.dylib -L/opt/gnat-gpl-2007-static/lib/gcc/powerpc-apple-darwin8.11.0/4.1.3/adalib/ -L./ -L/Users/simon/sf/tcladashell/src/.build_lib/ -L/opt/gnat-gpl-2007-static/lib/gcc/powerpc-apple-darwin8.11.0/4.1.3/adalib/ -L/usr/lib -ltk8.4 -ltcl8.4 -single_module -L/opt/gnat-gpl-2007-static/lib/gcc/powerpc-apple-darwin8.11.0/4.1.3/adalib/ -lgnarl-2007 -lgnat-2007 -Wl,-flat_namespace -shared-libgcc /Users/simon/sf/tcladashell/src/.build_lib/b~tash.o ...

which is quite similar except that (a) it works, (b) you have api.o
called up earlier.

HOWEVER -- it looks as though your api.adb itself explicitly calls
adainit, adafinal -- is that so? It shouldn't. My b~tash.adb defines
tashinit and tashfinal, and I believe these are what get called when
the dll is loaded/unloaded. adainit/adafinal are what GNAT generates
(by default?) when building an executable. I'd expect your b~api.adb
to define apiinit, apifinal.

I don't know why gnatdll doesn't give the same problem (it's not part
of the Mac build).

> I have problems seeing whats wrong. I have treid different settings
> for Library_Auto_Init, but with the same result.

I guess that's not the problem (but I think it should be "True", all
the same).

Martin Krischik

unread,
Feb 18, 2008, 2:04:47 AM2/18/08
to
news.broadpark.no schrieb:

> .NET. I made a small project and compiled it as follows:
>
> gnatmake -c api
> gnatbind -n api
> gnatdll -d api.dll api.ali
>

> Does anyone know what to do? The GPS project file look like this:

And where is the "-P" option which tells gnat make to actually use the
project file?

You should use:

gnat make -P api

and nothing else. Using gnatbind and gnatdll is more or less depreciated
- an up to date "gnat make" can do it all for you.

Have a look at the mkutils project which solves a similar problem:

http://code.google.com/p/mkutils

and here especially the build script (gnat make and nothing else):

http://code.google.com/p/mkutils/source/browse/trunk/All.btm

and the main project file:

http://code.google.com/p/mkutils/source/browse/trunk/MK_Utils.gpr

Regards

Martin
--
mailto://kris...@users.sourceforge.net
Ada programming at: http://ada.krischik.com

news.broadpark.no

unread,
Feb 18, 2008, 3:44:24 PM2/18/08
to
"Martin Krischik" <kris...@users.sourceforge.net> wrote in message
news:47b92e0f$1...@news.post.ch...

> news.broadpark.no schrieb:
>
>> .NET. I made a small project and compiled it as follows:
>>
>> gnatmake -c api
>> gnatbind -n api
>> gnatdll -d api.dll api.ali
>>
>> Does anyone know what to do? The GPS project file look like this:
>
> And where is the "-P" option which tells gnat make to actually use the
> project file?

The problem is that the GPS project file dows not work. Thus, no -P.

I found the solution to the problem. I added the following to the project
file:

for Library_Name use "Te";
for Library_Interface use ("api");

Now, I'm getting two default functions:

Teinit();
Tefinal();

I guess that's the same as adainit and adafinal. However, it seems that the
Ada core is still somewhat uninitialised. If I do the following call:

Ada.Text_IO.Put_Line("Error - Incorrect number of arguments");

Some kind of exception is raised and the program stops. If I do as follows:

Create(OutputFile, Name =>"C:\temp\dump.txt");
Ada.Text_IO.Set_Output(OutputFile);
Ada.Text_IO.Put_Line("Error - Incorrect number of arguments");

everything works fine.

Any idea?

Eirik

0 new messages