大家好,
我有一个静态库,然后我会将其与我的应用程序链接。我的开发环境是CMake,GCC(Linux、Mac)和MinGW(Windows)。
我可以在Linux和Windows上编译静态库而没有任何问题。 (在我的应用程序中甚至可以构建共享库)。
编辑:我将库编译为共享库,它也能够正常工作了!
我已经按照以下方式配置了CMakeFile来构建静态库:
add_library(centi STATIC ${base_srcs} ${crv_srcs} ${node_srcs} ${trnk_srcs} ${defl_srcs} ${infl_srcs} ${track_srcs} ${callback_srcs} ${extract_srcs})
在链接阶段,它会给出以下错误并以某种方式构建“libcenti.a”。Linking C static library
lib/libcenti.a /usr/bin/ranlib: file:
lib/libcenti.a(crv_in_rgn_to_bnry_img.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_initialize_by_circle.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_initialize_flgs.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_nodal_interval_min_and_max.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_remove_all_nodes.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_reset_nodal_forces.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_set_center_coords.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_set_left_ptch_rgn_pixs.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_set_out_rgn_mean_and_var.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_set_para.c.o) has
no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_set_right_ptch_rgn_pixs.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_to_in_rgn_hist.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(crv_to_out_rgn_pixs.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(trnk_initialize_by_circle.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(trnk_initialize_by_image_frame.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(trnk_stk_paint_nodes_and_pixs.c.o)
has no symbols /usr/bin/ranlib: file:
lib/libcenti.a(trnk_stk_to_inner_defl_ordn.c.o)
has no symbols
但是当我将上述库与我的应用程序链接时,它会给出"未定义符号"错误:Undefined symbols:
"_setActiveDrawingTrunk", referenced
from:
RzPluginAlgoCnty::initCallBacks()
in RzPluginAlgoCnty.cpp.o
RzPluginAlgoCnty::clearCallBacks()
in RzPluginAlgoCnty.cpp.o
_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_bg_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_bg_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_extract_contour_update_tracking in
libcenti.a(extract_contour_update_tracking.c.o)
_extract_contour_update_tracking in
libcenti.a(extract_contour_update_tracking.c.o)
"_updateCurveUICallBack", referenced
from:
RzPluginAlgoCnty::initCallBacks()
in RzPluginAlgoCnty.cpp.o
RzPluginAlgoCnty::initBulkCallBacks()
in RzPluginAlgoCnty.cpp.o
RzPluginAlgoCnty::clearCallBacks()
in RzPluginAlgoCnty.cpp.o
_bg_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_bg_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.c.o)
_crv_update_1time in libcenti.a(crv_update_ordn.c.o)
_crv_update_1time in libcenti.a(crv_update_ordn.c.o) ld:
symbol(s) not found
有什么建议吗?在 Mac 上构建静态库时,是否需要添加任何特殊参数?
编辑: 我将库编译为共享库,它可以正常工作了!
libtool
而不是ar
和ranlib
。我认为有一个选项可以抑制它,但我目前找不到它。还请参见Silence “table of contents is empty” warning。 - jww