ada - 如何使用gnatmake和Ada共享库进行编译和链接?

标签 ada gnat

我在重新编译花店图书馆的申请时遇到麻烦。事实证明,我的花店问题更大(来自最新的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 / 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:警告:“ SYSTEM.INTERRUPT_MANAGEMENT.OPERATIONS”是内部GNAT单元
posix-implementation.gpb:45:06:警告:此单元的使用不可移植且取决于版本
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-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):更多对fetch_errno的未定义引用
./posix-implementation.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时出错
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):更多对fetch_errno的未定义引用
./posix-implementation.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文件正确建立,因此我不知道它来自哪里。

最佳答案

好的,这原来是很大的痛苦,但我发现了。

花店绑定既可以作为共享库又可以作为静态库(都已安装)使用。您需要链接到库以解析所有引用(我永远无法将库源实际编译到我的应用程序中)。一旦传递了参数以告知编译阶段有关库的信息,就必须提供要解析的.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,以将它们传递到正确的位置!

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

关于ada - 如何使用gnatmake和Ada共享库进行编译和链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3902597/

相关文章:

linux - 更新 GPS Community Edition 2019 IDE 的编译器

ada - 将导入的 C 指针包装在相同大小的 Ada 标记类型中

types - 将类型转换为字符串

opencv - 如何为 GNAT 绑定(bind)到 OpenCV?

ada - 跟踪 Ada 程序的执行

ada - 学习艾达 : Source Code and Newbie "Forum"?

ada - 在 Ada Last_Chance_Handler 中打印异常消息

sockets - Ada - 使用 GNAT.Sockets 发送 HTTP 响应

ada - 关于阿达(Ada)的 "range"

arrays - 为什么字符串需要初始化一个初始值?