如何使用 gnatmake 与 Ada 共享库进行编译和链接?
我在花店图书馆再次编译申请人时遇到问题。结果我对 florist 有一个更大的问题(最新的 2010 Adacore GPL 下载和 Debian 存档中的 2009 版本都产生相同的错误)。 Florist 有一些低级问题,但当我查看生成的文件时,它似乎正确包含 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 demo 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-cc 文件来看,一切看起来都是正确的。有人对如何解决这个问题有什么建议吗? Florist 的 make 文件构建正确,所以我不知道它来自哪里。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,事实证明这很痛苦,但我发现了。
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 参数以及 -largs 以将它们传递到正确的位置!
我现在很高兴。希望这对其他人有帮助。
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.
这是使用 GNAT 项目与 Florist 进行构建的简单示例。我假设
$ADA_PROJECT_PATH
包含安装florist.gpr
的目录(在我的例子中,$HOME/local/lib/gnat
)。示例程序(我在网上找不到任何简单的 Florist 演示,有吗?),在
id.adb
中:项目文件 (
id.gpr
) ,与 id.adb 位于同一目录中:构建
并运行:
This is a simple example of using a GNAT Project to build with Florist. I assume that
$ADA_PROJECT_PATH
includes the directory whereflorist.gpr
is installed (in my case,$HOME/local/lib/gnat
).The sample program (I couldn't find any simple Florist demos on the web, are there any?), in
id.adb
:The project file (
id.gpr
), in the same directory asid.adb
:Build with
and run:
它看起来像是非常普通的链接错误。您的 .h 文件、Ada 目标文件和 C 链接库之间的某些内容不太匹配。但很难说清楚是什么。
您最好的选择是寻找可能遇到相同问题的其他花店用户。他们的项目页面位于 SourceForge 上,但看起来并没有那么糟糕过去 6 年一直活跃。由于最新版本已经那么旧了,因此您可能需要一个那么旧的编译器(和操作系统?)才能使用它。恶心。
It looks like pretty garden-variety link errors. Something between your .h files, your Ada object files, and your C link libraries isn't quite mating up. Tough to tell what though.
Your best bet is going to be looking for other Florist users who may have run into the same issue. Their project page is on SourceForge here, but it looks like it hasn't been horribly active for the last 6 years. Since the latest version there is that old, it could be that you need a compiler (and OS?) that old for it to work with. Ick.