0
votes

I am not very familiar with the linking especially on the *nix/Mac.

I am trying to manually link the binary to perform some testing. I have 2 sets of libraries against which I need to link my binary: first library is installed at /usr/local/lib and it is called cppunit, the second is installed at ~/mylib/lib and it is called libmylib.

So I grabbed the link command modified it accordingly and tried to run the binary. Unfortunately I got the error message which reads:

dyld: Library not loaded: /usr/local/lib/libmylib

Unfortunately I believe I can't modify the link command so that it reads:

-L/usr/local/lib/cppunit -L~/mylib/lib/mylib

So how do I modify the link command so that the linker will find the library in its place?

Here are the complete link command I tried:

g++ -mmacosx-version-min=10.6 -o test_gui   test_gui_asserthelper.o test_gui_test.o test_gui_testableframe.o test_gui_rect.o test_gui_size.o test_gui_point.o test_gui_region.o test_gui_bitmap.o test_gui_colour.o test_gui_desktopenv.o test_gui_ellipsization.o test_gui_measuring.o test_gui_affinematrix.o test_gui_boundingbox.o test_gui_config.o test_gui_bitmapcomboboxtest.o test_gui_bitmaptogglebuttontest.o test_gui_bookctrlbasetest.o test_gui_buttontest.o test_gui_checkboxtest.o test_gui_checklistboxtest.o test_gui_choicebooktest.o test_gui_choicetest.o test_gui_comboboxtest.o test_gui_dataviewctrltest.o test_gui_datepickerctrltest.o test_gui_frametest.o test_gui_gaugetest.o test_gui_gridtest.o test_gui_headerctrltest.o test_gui_htmllboxtest.o test_gui_hyperlinkctrltest.o test_gui_itemcontainertest.o test_gui_label.o test_gui_listbasetest.o test_gui_listbooktest.o test_gui_listboxtest.o test_gui_listctrltest.o test_gui_listviewtest.o test_gui_markuptest.o test_gui_notebooktest.o test_gui_ownerdrawncomboboxtest.o test_gui_pickerbasetest.o test_gui_pickertest.o test_gui_radioboxtest.o test_gui_radiobuttontest.o test_gui_rearrangelisttest.o test_gui_richtextctrltest.o test_gui_searchctrltest.o test_gui_simplebooktest.o test_gui_slidertest.o test_gui_spinctrldbltest.o test_gui_spinctrltest.o test_gui_textctrltest.o test_gui_textentrytest.o test_gui_togglebuttontest.o test_gui_toolbooktest.o test_gui_treebooktest.o test_gui_treectrltest.o test_gui_treelistctrltest.o test_gui_virtlistctrltest.o test_gui_webtest.o test_gui_windowtest.o test_gui_dialogtest.o test_gui_clone.o test_gui_evtlooptest.o test_gui_propagation.o test_gui_keyboard.o test_gui_exec.o test_gui_fonttest.o test_gui_image.o test_gui_rawbmp.o test_gui_htmlparser.o test_gui_htmlwindow.o test_gui_accelentry.o test_gui_menu.o test_gui_guifuncs.o test_gui_selstoretest.o test_gui_garbage.o test_gui_safearrayconverttest.o test_gui_settings.o test_gui_socket.o test_gui_boxsizer.o test_gui_wrapsizer.o test_gui_toplevel.o test_gui_valnum.o test_gui_clientsize.o test_gui_setsize.o test_gui_xrctest.o    -L/Users/AlenaKorot/wxWidgets3.0/buildMac/lib -ldl  -arch i386 -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL   -lwx_osx_cocoau_webview-3.0 -lwx_osx_cocoau_richtext-3.0  -lwx_osx_cocoau_media-3.0 -framework QTKit -lwx_osx_cocoau_xrc-3.0  -lwx_baseu_xml-3.0 -lexpat -lwx_osx_cocoau_adv-3.0  -lwx_osx_cocoau_html-3.0  -lwx_osx_cocoau_core-3.0  -lwx_baseu_net-3.0  -lwx_baseu-3.0    -lwxtiff-3.0 -lwxjpeg-3.0 -lwxpng-3.0  -framework WebKit  -lwxregexu-3.0   -L/usr/local/lib -lcppunit -arch i386 -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL  -lz -lpthread -liconv  -lz -lpthread -liconv
1
Were you able to get anywhere with this?BobTuckerman
@BobTuckerman, yes, I did. Apparently there was a mix of directories.Igor
Nice, want to add that as an answer?BobTuckerman

1 Answers

1
votes

Essentially, the issue is that your library isn't in the default library paths for g++. You'll have to explicitly add it to the list of arguments for g++ to know where it is.

1) Add the mylib compiled source

Typically this is a .a (compiled source archive) or a .o (compiled source) file. Figure out where it is in the 'mylib' library, and add it to your argument list, in the same way the other .o files are listed.

g++ <blah blah> -o myfile /home/username/mylib/mylib.o

When you start to include things from your library, you will get compile errors if the header includes aren't in your g++ argument list.

2) Add the 'mylib' header includes

Look in the mylib directory for the include dir. If you don't add this, you'll get compilation errors whenever you try to #include something from the library.

Add it to the path using the -I flag. Like so:

g++ <blah blah> -I/home/username/mylib/include

Lastly, if you aren't using a makefile for compilation, I'd recommend putting together a simple makefile for your target.