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;
I suspect your problem is the 'for Library_Auto_Init use
"False";'. Why is this here?
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
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).
> .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
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