如何使用gnatmake和Ada共享库进行编译和链接? [英] How do I compile and link using gnatmake with an Ada shared library?

查看:122
本文介绍了如何使用gnatmake和Ada共享库进行编译和链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在重新编译花店图书馆的申请时遇到麻烦。事实证明,我的花店问题更大(最新的2010 Adacore GPL下载和Debian存档中的2009版本都出现了相同的错误结果)。花店有一些低级问题,但是当我查看生成的文件时,似乎正确地包含了errno.h。



这是我建立花店时发生的事情:



gcc-4.4 -c -I / usr / share / ada / adainclude / florist demo.adb
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- /usr/share/ada/adainclude/florist/posix.adb
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude /花店-I- /usr/share/ada/adainclude/florist/posix-io.adb
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- / usr /share/ada/adainclude/florist/posix-terminal_functions.adb
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- / usr / share / ada / adainclude /florist/posix-c.adb
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- / usr / share / ada / adainclude / florist / posix-implementation .adb
posix-implementation.gpb:45:06:警告: SYSTEM.INTERRUPT_MANAGEMENT.OPERATIONS是内部GNAT单元
posix-implementation.gpb:45:06:警告:使用此单元是n依赖于版本的便携式
posix-implementation.gpb:47:06:警告: SYSTEM.SOFT_LINKS是内部GNAT单元
posix-implementation.gpb:47:06:警告:使用该单元的单位不可移植且取决于版本
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- / usr / share / ada / adainclude / florist / ada_streams.ads
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- /usr/share/ada/adainclude/florist/posix-permissions.adb
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- /usr/share/ada/adainclude/florist/posix-permissions-implementation.adb
gcc-4.4 -c -I./ -I / usr / share / ada / adainclude / florist -I- /usr/share/ada/adainclude/florist/posix-process_identification.adb
gnatbind -I / usr / share / ada / adainclude / florist -x demo.ali
gnatlink demo.ali -o demoapp
./posix-implementation.o:在函数posix__implementation__set_ada_error_code中:
posix-implementation.adb :(。 text + 0x19e):对`store_errno'
的未定义引用。/posix-impleme ntation.o:在函数posix__implementation__get_ada_error_code中:
posix-implementation.adb :(。text + 0x1ab):对fetch_errno的未定义引用
。/ posix-implementation.o在函数posix__implementation__raise_posix_error中:
posix-implementation.adb :(。text + 0x234):未定义引用'fetch_errno'
./posix-implementation.o:在函数posix__implementation__check__2中:
posix-implementation。 adb :(。text + 0x2e5):未定义引用'fetch_errno'
./posix-implementation.o:在函数`posix__implementation__check__3'中:
posix-implementation.adb :(。text + 0x313):未定义对`fetch_errno'
的引用。/posix-implementation.o:在函数`posix__implementation__check_nneg'中:
posix-implementation.adb :(。text + 0x332):未定义对`fetch_errno'$ b $的引用b ./posix-implementation.o:posix-implementation.adb:(.text+0x34e):
之后是对`fetch_errno'的更多未定义引用./posix-implementation.o:在函数`nosys_neg_one'中:
posix-implemen tation.adb :(。text + 0xaef):未定义对`store_errno'
的引用./posix-implementation.o:在函数`notsup_neg_one'中:
posix-implementation.adb :(。text + 0xb15 ):对`store_errno'
的未定义引用./posix-implementation.o:在函数posix__implementation__restore_signals_and_raise_posix_error'中:
posix-implementation.adb :(。text + 0xc88):对fetch_errno'$的未定义引用b $ b ./posix.o:在函数posix__system_name中:
posix.adb :(。text + 0x2f98):对`__gnat_florist_uname的未定义引用
./posix.o:在函数posix__node_name中':
posix.adb :(。text + 0x2fef):未定义对__gnat_florist_uname的引用
./posix.o:在函数posix__release中:
posix.adb :(。text + 0x3049):未定义引用__gnat_florist_uname
./posix.o:在函数posix__version中:
posix.adb :(。text + 0x30a6)未定义引用__gnat_florist_uname
./posix.o:在函数posix__machine中:
posix.adb :(。text + 0x3103):对`__gnat的未定义引用_florist_uname'
./posix.o:在函数posix__host_to_network_byte_order中:
posix.adb :(。text + 0x4627):未定义对c_htonl的引用
./posix.o:在函数`posix__host_to_network_byte_order__2':
posix.adb :(。text + 0x4642):对`c_htons'
的未定义引用./posix.o:在函数`posix__network_to_host_byte_order'中:
posix.adb: (.text + 0x4655):对'c_ntohl'
的未定义引用./posix.o:在函数'posix__network_to_host_byte_order__2'中:
posix.adb :(。text + 0x4670):对'c_ntohs'的未定义引用
./posix-io.o:在函数posix__io__open中:
posix-io.adb :(。text + 0x4d1):对`__gnat_florist_open'
的未定义引用./posix-io .o:在函数posix__io__open_or_create中:
posix-io.adb :(。text + 0xfca):未定义对__gnat_florist_open的引用
collect2:ld返回1退出状态
gnatlink:错误调用/usr/bin/gcc-4.4
gnatmake时:***链接失败。
josh @ Mini10:〜/ Demo $ gnatbind -I / usr / share / ada / adainclude / florist -I / usr / include演示
josh @ Mini10:〜/ Demo $ gnatlink演示
./posix-implementation.o:在函数posix__implementation__set_ada_error_code中:
posix-implementation.adb :(。text + 0x19e):未定义对store_errno的引用
./posix-implementation.o:在函数`posix__implementation__get_ada_error_code':
posix-implementation.adb :(。text + 0x1ab):对`fetch_errno'
的未定义引用./posix-implementation.o:在函数posix__implementation__raise_posix_error'中:
posix-implementation.adb :(。text + 0x234):未定义引用'fetch_errno'
./posix-implementation.o:在函数posix__implementation__check__2'中:
posix-implementation.adb :(。text + 0x2e5):对`fetch_errno'
的未定义引用./posix-implementation.o:在函数posix__implementation__check__3'中:
posix-implementation.adb :(。text + 0x313):对fetch_errno的未定义引用'
./posix-implementation.o:在功能上'posix__implementation__check_nneg':
posix-implementation.adb :(。text + 0x332):对`fetch_errno'
的未定义引用./posix-implementation.o:posix-implementation.adb:(.text+0x34e ):$ f $ _errno后面还有更多对fetch_errno的未定义引用.o:在函数`nosys_neg_one'中的
posix-implementation.adb :(。text + 0xaef):对`store_errno的未定义引用'
./posix-implementation.o:在函数`notsup_neg_one'中:
posix-implementation.adb :(。text + 0xb15):对`store_errno'
的未定义引用./posix- Implementation.o:在函数posix__implementation__restore_signals_and_raise_posix_error中:
posix-implementation.adb :(。text + 0xc88):对fetch_errno的未定义引用
./posix.o:在函数posix__system_name中:
posix.adb :(。text + 0x2f98):未定义对__gnat_florist_uname的引用
./posix.o:在函数posix__node_name中:
posix.adb :(。text + 0x2fef) :对`__gnat_florist_uname'
的未定义引用./posix.o:在函数posix中__release':
posix.adb :(。text + 0x3049):未定义对__gnat_florist_uname的引用
./posix.o:在函数posix__version中:
posix.adb :(。 text + 0x30a6):未定义引用__gnat_florist_uname
./posix.o:在函数posix__machine中:
posix.adb :(。text + 0x3103)未定义引用__gnat_florist_uname
./posix.o:在函数posix__host_to_network_byte_order中:
posix.adb :(。text + 0x4627):对c_htonl的未定义引用
./posix.o:在函数posix__host_to_network_byte_order__2中:
posix.adb :(。text + 0x4642):对`c_htons'
的未定义引用./posix.o:在函数posix__network_to_host_byte_order中:
posix.adb :(。text + 0x4655):未定义对`c_ntohl'
的引用./posix.o:在函数`posix__network_to_host_byte_order__2'中:
posix.adb :(。text + 0x4670):未定义对`c_ntohs'
的引用./posix-io.o:在函数posix__io__open中:
posix-io.adb :(。text + 0x4d1):对`__gnat_florist_open'
的未定义引用./posix-io .o:在函数posix__io__open_or_create中:
posix-io.adb :(。text + 0xfca):未定义对__gnat_florist_open的引用
collect2:ld返回1退出状态
gnatlink:错误在调用/usr/bin/gcc-4.4



时,如果正确包含errno.h出现此错误,这似乎很常见。但是据我从posix-c.c文件可以看出,这一切看起来都是正确的。有人对如何解决这个问题有任何建议吗?花店的make文件可以正确构建,因此我不知道它来自哪里。

解决方案

确定,结果很大



Florist绑定既可以用作共享库,也可以用作静态库(两者都已安装)。您需要链接到库以解析所有引用(我永远无法将库源实际编译到我的应用程序中)。一旦传递了参数以告知编译阶段有关库的信息,就必须提供要解析的.ads(至少)文件。



最终的解决方案是这样:



gnatmake -aI / usr / share / ada / adainclude / florist -aO / usr / lib / ada / adalib / florist demo.adb -largs -lflorist



-aI 提供库广告文件的路径。 -aO 提供(在本例中)libflorist.so库文件的路径,最后(这是棘手的一个)您必须传递 -lflorist 告诉它这是什么共享库...但是传递它是行不通的。您必须在其前面放置一个 -largs (用于编译和链接器),以便传递编译阶段的参数!没有它,那些阶段就永远看不到论点!



因此,每个人都有!为了在Linux(GCC)下针对共享的Ada库编译和链接代码,您需要提供库的标头/规范,库的位置和-llibname参数以及-larg,以将它们传递到正确的位置! / p>

我现在很高兴。希望这对其他人有帮助。


I am having trouble compile an applicant again the Florist library. Turns out I have a larger issue with florist (same error results from both newest 2010 Adacore GPL download and 2009 version in Debian's archive). Florist has some low-level issues but when I look through the generated files it seems to be including errno.h correctly.

Here is what happens when I build florist:

gcc-4.4 -c -I/usr/share/ada/adainclude/florist demo.adb gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix.adb gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix-io.adb gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix-terminal_functions.adb gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix-c.adb gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix-implementation.adb posix-implementation.gpb:45:06: warning: "SYSTEM.INTERRUPT_MANAGEMENT.OPERATIONS" is an internal GNAT unit posix-implementation.gpb:45:06: warning: use of this unit is non-portable and version-dependent posix-implementation.gpb:47:06: warning: "SYSTEM.SOFT_LINKS" is an internal GNAT unit posix-implementation.gpb:47:06: warning: use of this unit is non-portable and version-dependent gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/ada_streams.ads gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix-permissions.adb gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix-permissions-implementation.adb gcc-4.4 -c -I./ -I/usr/share/ada/adainclude/florist -I- /usr/share/ada/adainclude/florist/posix-process_identification.adb gnatbind -I/usr/share/ada/adainclude/florist -x demo.ali gnatlink demo.ali -o demoapp ./posix-implementation.o: In function `posix__implementation__set_ada_error_code': posix-implementation.adb:(.text+0x19e): undefined reference to `store_errno' ./posix-implementation.o: In function `posix__implementation__get_ada_error_code': posix-implementation.adb:(.text+0x1ab): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__raise_posix_error': posix-implementation.adb:(.text+0x234): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__check__2': posix-implementation.adb:(.text+0x2e5): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__check__3': posix-implementation.adb:(.text+0x313): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__check_nneg': posix-implementation.adb:(.text+0x332): undefined reference to `fetch_errno' ./posix-implementation.o:posix-implementation.adb:(.text+0x34e): more undefined references to `fetch_errno' follow ./posix-implementation.o: In function `nosys_neg_one': posix-implementation.adb:(.text+0xaef): undefined reference to `store_errno' ./posix-implementation.o: In function `notsup_neg_one': posix-implementation.adb:(.text+0xb15): undefined reference to `store_errno' ./posix-implementation.o: In function `posix__implementation__restore_signals_and_raise_posix_error': posix-implementation.adb:(.text+0xc88): undefined reference to `fetch_errno' ./posix.o: In function `posix__system_name': posix.adb:(.text+0x2f98): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__node_name': posix.adb:(.text+0x2fef): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__release': posix.adb:(.text+0x3049): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__version': posix.adb:(.text+0x30a6): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__machine': posix.adb:(.text+0x3103): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__host_to_network_byte_order': posix.adb:(.text+0x4627): undefined reference to `c_htonl' ./posix.o: In function `posix__host_to_network_byte_order__2': posix.adb:(.text+0x4642): undefined reference to `c_htons' ./posix.o: In function `posix__network_to_host_byte_order': posix.adb:(.text+0x4655): undefined reference to `c_ntohl' ./posix.o: In function `posix__network_to_host_byte_order__2': posix.adb:(.text+0x4670): undefined reference to `c_ntohs' ./posix-io.o: In function `posix__io__open': posix-io.adb:(.text+0x4d1): undefined reference to `__gnat_florist_open' ./posix-io.o: In function `posix__io__open_or_create': posix-io.adb:(.text+0xfca): undefined reference to `__gnat_florist_open' collect2: ld returned 1 exit status gnatlink: error when calling /usr/bin/gcc-4.4 gnatmake: *** link failed. josh@Mini10:~/Demo$ gnatbind -I/usr/share/ada/adainclude/florist -I/usr/include demo josh@Mini10:~/Demo$ gnatlink demo ./posix-implementation.o: In function `posix__implementation__set_ada_error_code': posix-implementation.adb:(.text+0x19e): undefined reference to `store_errno' ./posix-implementation.o: In function `posix__implementation__get_ada_error_code': posix-implementation.adb:(.text+0x1ab): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__raise_posix_error': posix-implementation.adb:(.text+0x234): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__check__2': posix-implementation.adb:(.text+0x2e5): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__check__3': posix-implementation.adb:(.text+0x313): undefined reference to `fetch_errno' ./posix-implementation.o: In function `posix__implementation__check_nneg': posix-implementation.adb:(.text+0x332): undefined reference to `fetch_errno' ./posix-implementation.o:posix-implementation.adb:(.text+0x34e): more undefined references to `fetch_errno' follow ./posix-implementation.o: In function `nosys_neg_one': posix-implementation.adb:(.text+0xaef): undefined reference to `store_errno' ./posix-implementation.o: In function `notsup_neg_one': posix-implementation.adb:(.text+0xb15): undefined reference to `store_errno' ./posix-implementation.o: In function `posix__implementation__restore_signals_and_raise_posix_error': posix-implementation.adb:(.text+0xc88): undefined reference to `fetch_errno' ./posix.o: In function `posix__system_name': posix.adb:(.text+0x2f98): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__node_name': posix.adb:(.text+0x2fef): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__release': posix.adb:(.text+0x3049): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__version': posix.adb:(.text+0x30a6): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__machine': posix.adb:(.text+0x3103): undefined reference to `__gnat_florist_uname' ./posix.o: In function `posix__host_to_network_byte_order': posix.adb:(.text+0x4627): undefined reference to `c_htonl' ./posix.o: In function `posix__host_to_network_byte_order__2': posix.adb:(.text+0x4642): undefined reference to `c_htons' ./posix.o: In function `posix__network_to_host_byte_order': posix.adb:(.text+0x4655): undefined reference to `c_ntohl' ./posix.o: In function `posix__network_to_host_byte_order__2': posix.adb:(.text+0x4670): undefined reference to `c_ntohs' ./posix-io.o: In function `posix__io__open': posix-io.adb:(.text+0x4d1): undefined reference to `__gnat_florist_open' ./posix-io.o: In function `posix__io__open_or_create': posix-io.adb:(.text+0xfca): undefined reference to `__gnat_florist_open' collect2: ld returned 1 exit status gnatlink: error when calling /usr/bin/gcc-4.4

It seems that this error is common if there is an issue with errno.h being correctly included. But as far as I can tell from the posix-c.c file it all looks correct. Anybody have any suggestions on how to resolve this? Florist's make file builds correctly so I don't know where this is coming from.

解决方案

OK, this turned out to be big pain but I found it.

The Florist binding is available both as a shared library and a static library (both are installed). You need to link against the library to resolve all references (I could never actually compile the library source into my application). Once you pass the argument to tell the compilation stage about the library you have to provide the .ads (at least) files to resolve against.

The final solution ended being this:

gnatmake -aI/usr/share/ada/adainclude/florist -aO/usr/lib/ada/adalib/florist demo.adb -largs -lflorist

-aI provides the path to the library's ads files. -aO provides the path to the (in this case) libflorist.so library file and finally (and this is the tricky one) you have to pass -lflorist to tell it what shared library this all is...but passing it won't work. You have to place a -largs in front of it (for the compile and linker) in order for the compilation phase to be passed the parameter! Without it those phases never see the argument!

So there you are everyone! In order to compile and link code against a shared Ada library under Linux (GCC) you need to provide the Library's Headers/Specs, the Library location, and the -llibname argument along with the -largs to pass those into the right places!

I'm happy now. Hope this helps someone else.

这篇关于如何使用gnatmake和Ada共享库进行编译和链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆