本文介绍了使用CMake和GCC在Mac上构建静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 所有问候, 我有一个静态库,我稍后会与我的应用程序链接。我的开发环境是CMake,GCC(Linux,Mac),MinGW(Windows)。 我可以在Linux和Windows上无任何问题地编译静态库。 (我甚至可以在Mac上的应用程序中创建共享库)。 编辑:我将库编译为共享库并且工作正常! strong> 我已经将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。 $链接C静态库$ b $ lib / libcenti.a / usr / bin / ranlib:file: lib / libcenti.a(crv_in_rgn_to_bnry_img.co )没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_initialize_by_circle.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_initialize_flgs.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_nodal_interval_min_and_max.co)没有符号/ usr /斌/ ranlib:file: lib / libcenti.a(crv_remove_all_nodes.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_reset_nodal_forces.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_set_center_coords.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_set_left_ptch_rgn_pixs.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_set_out_rgn_mean_and_var.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_set_para.co)有没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_set_right_ptch_rgn_pixs.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_to_in_rgn_hist.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(crv_to_out_rgn_pixs.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(trnk_initialize_by_circle.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(trnk_initialize_by_image_frame.co)没有符号/ u sr / bin / ranlib:file: lib / libcenti.a(trnk_stk_paint_nodes_and_pixs.co)没有符号/ usr / bin / ranlib:file: lib / libcenti.a(trnk_stk_to_inner_defl_ordn。 co)没有符号 但是当我将上面的库链接到我的应用程序时, 未定义符号错误: 未定义的符号:_setActiveDrawingTrunk,引用来自: RzPluginAlgoCnty :: initCallBacks() in RzPluginAlgoCnty.cpp.o RzPluginAlgoCnty :: clearCallBacks() in RzPluginAlgoCnty.cpp.o _trnk_trck_ordn in libcenti.a(trnk_trck_ordn。 (trnk_trck_ordn.co) _trnk_trck_ordn in libcenti.a(trnk_trck_ordn.co) _trnk_trck_ordn in libcenti.a(trnk_trck_ordn.co) _bg_trnk_trck_ordn in libcenti.a(trnk_trck_ordn.co) libcenti.a中的_bg_trnk_trck_ordn(trnk_trck_ordn.co) _extract_contour_update_tracking in libcenti.a(extract_contour_update_tracking.co) _extract_contour_update_tracking in libcenti.a(extract_contour_update_tracking.co)_updateCurveUICallBack,引用 from: RzPluginAlgoCnty :: initCallBacks( )RzPluginAlgoCnty.cpp.o中的 RzPluginAlgoCnty :: initBulkCallBacks()中的 RzPluginAlgoCnty.cpp.o中的 RzPluginAlgoCnty.cpp中的RzPluginAlgoCnty :: clearCallBacks()。在libcenti.a(trnk_trck_ordn.co)中 _bg_trnk_trck_ordn(trnk_trck_ordn.co)libcenti.a中的 _bg_trnk_trck_ordn(trnk_trck_ordn.co) libcenti.a中的_crv_update_1time(crv_update_ordn.co)$ lib $ b中的_crv_update_1time .a(crv_update_ordn.co)ld:找不到符号 任何提示?在Mac上构建静态库时,我应该添加任何特殊参数吗? 编辑:我将库编译为SHARED库,它工作正常! ! 解决方案这里讨论MacOSX上静态库的类似问题: http://lists.macosforge.org/pipermail/macports-tickets/2008-June/010680.html 尝试做一个完整的清理并运行一个不平行的构建。 和 this指南建议安装macports,然后sudo port install autogen autoconf automake nano libtool libsdl patchutils subversion wget gmake,然后导出PATH =/ usr / local / bin:/ usr / local / sbin:$ PATH Greetings all,I have a static library which I later link with my application. My development environment is CMake, GCC (Linux, Mac), MinGW (Windows).I can compile the static library without any problem on Linux and Windows. (I can even build shared libraries in my application on Mac).EDIT: I compiled the library as a SHARED library and it worked fine!!I have configured CMakeFile as follows to build the static library:add_library(centi STATIC ${base_srcs} ${crv_srcs} ${node_srcs} ${trnk_srcs} ${defl_srcs} ${infl_srcs} ${track_srcs} ${callback_srcs} ${extract_srcs})During linking phase, it gives following errors and build the "libcenti.a" somehow.Linking C static librarylib/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) hasno 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 symbolsBut when I link above library with my application, it gives "Undefined symbols" errors:Undefined symbols:"_setActiveDrawingTrunk", referencedfrom: 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 inlibcenti.a(extract_contour_update_tracking.c.o) _extract_contour_update_tracking inlibcenti.a(extract_contour_update_tracking.c.o)"_updateCurveUICallBack", referencedfrom: 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 foundAny tips ? Should I add any special parameters when building static libraries on Mac?EDIT:I compiled the library as a SHARED library and it worked fine!! 解决方案 The similar problem with static libraries on MacOSX is discussed here: http://lists.macosforge.org/pipermail/macports-tickets/2008-June/010680.htmlTry to do a full clean and run a not-parallel build.And this guide recommends to install macports, then "sudo port install autogen autoconf automake nano libtool libsdl patchutils subversion wget gmake", and then export PATH="/usr/local/bin:/usr/local/sbin:$PATH" 这篇关于使用CMake和GCC在Mac上构建静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 00:17