是否可以为 DLL/SO 构建指定特定标志/定义?
如何为仅 DLL 构建指定一些独特的标志。默认情况下,libtool 添加 -DDLL_EXPORT
这对于大多数遵循 GNU 约定的项目来说都很好,但是如果我使用 Boost,例如,我可能需要为我的库标志指定: -DDLL_EXPORT - DBOOST_ALL_DYN_LINK
仅适用于 DLL 构建,有时我也需要条件构建,因此我需要 DLL/SO 构建的一些特定定义。
不幸的是,我找不到如何使用 libtool 执行此操作的方法,我应该使用什么标志?
PS: 甚至不要尝试建议迁移到 CMake。
示例:
我使用链接到 bar 的库 foo 并需要 -DBAR_EXPORTS 来仅获取动态库的符号。
有没有像
libfoo_la_dynamic_CXXFLAGS = -DBAR_EXPORTS
任何人?
替代解决方案:(相当丑陋)
创建一个文件`defines.h
#if defined(PIC) || defined(DLL_EXPORT)
#define BAR_EXPORTS
#endif
然后:
libfoo_la_CXXFLAGS += -include defines.h
丑陋但应该可以工作。
How can I specify some unique flags for DLL only builds. By default libtool adds -DDLL_EXPORT
which is fine for most projects that follow GNU conventions, but if I work, for example, with Boost I may need to specify for my library flags: -DDLL_EXPORT -DBOOST_ALL_DYN_LINK
for DLL only builds, also sometimes I want conditional builds so I need some specific defines for DLL/SO build.
Unfortunately I can't find a way how to do this with libtool, what flags should I use?
P.S.: Don't even try to suggest to move to CMake.
Example:
I use library foo that links to bar and requires -DBAR_EXPORTS to get symbols for dynamic library only.
Is there something like
libfoo_la_dynamic_CXXFLAGS = -DBAR_EXPORTS
Anybody?
Alternative Solution: (quite ugly)
Create a file `defines.h
#if defined(PIC) || defined(DLL_EXPORT)
#define BAR_EXPORTS
#endif
And then:
libfoo_la_CXXFLAGS += -include defines.h
Ugly but should work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以默认禁用构建共享库,然后
可以将
AM_CONDITIONAL
与--enabled-shared
结合使用,并在明确请求共享库时设置额外的定义。 IOW,启用构建静态或共享,但不能同时构建两者。You can disable building shared library by default with
then you can use
AM_CONDITIONAL
combined with--enabled-shared
and set the extra definitions if shared library is explicitly requested. IOW, enable building static or shared, but not both at the same time.不是那么漂亮,但是你可以使用 条件 来检查是否定义了 DLL_EXPORT 以及是否定义了您需要的其他内容?
我不太擅长使用自动工具,我更喜欢 CMake,但你似乎非常反对。
Not that pretty, but could you use a conditional to check if DLL_EXPORT is defined and if it is define the others you need?
I'm not that good with autotools, I prefer CMake but you seem quite against that.