Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Use a shared object or dynamic library

Main problem...

I made an application that uses a library (.dylib) but is unable to locate the first function it tries to use (it compiles but fails at runtime to locate a function). The application does not crash it simply exits with an error.


The error is from this line:

version = (void *)dlsym(handle, "km_c_version");


More details:

I want to use a library from a company called TotalPhase that makes a USB to CAN peripheral, called the komodo (they also make USB to I2C, and SPI). They provide a library and the source code.


My application should use the library. I have a couple questions with regard to libraries:

1) since they provide the source should I just include the source in my project and not even use the library?

2) I have tried several times to create a project that builds the library as a .dylib (they provide a .so)



The project to build the .dylib compiles and I can see the functions in the .dylib. The name of the library is "libkomodo.dylib. When I use the command line tool nm I get a listing that seems to include the function in question "km_c_version"


Proton:Debug wayne$ nm -mg libkomodo.dylib

(undefined) external __NSGetExecutablePath (from libSystem)

(undefined) external ___sprintf_chk (from libSystem)

(undefined) external ___stack_chk_fail (from libSystem)

(undefined) external ___stack_chk_guard (from libSystem)

(undefined) external ___strncpy_chk (from libSystem)

(undefined) external _close (from libSystem)

(undefined) external _dlopen (from libSystem)

(undefined) external _dlsym (from libSystem)

(undefined) external _free (from libSystem)

(undefined) external _getcwd (from libSystem)

0000000000000e20 (__TEXT,__text) external _km_acquire

0000000000001650 (__TEXT,__text) external _km_can_async_collect

00000000000015a0 (__TEXT,__text) external _km_can_async_submit

0000000000001230 (__TEXT,__text) external _km_can_auto_bitrate

00000000000012b0 (__TEXT,__text) external _km_can_auto_bitrate_ext

00000000000011b0 (__TEXT,__text) external _km_can_bitrate

0000000000001130 (__TEXT,__text) external _km_can_bus_timeout

00000000000010b0 (__TEXT,__text) external _km_can_configure

0000000000000fa0 (__TEXT,__text) external _km_can_query_bus_state

0000000000001510 (__TEXT,__text) external _km_can_read

00000000000013b0 (__TEXT,__text) external _km_can_target_power

00000000000016d0 (__TEXT,__text) external _km_can_write

0000000000000af0 (__TEXT,__text) external _km_close

00000000000014a0 (__TEXT,__text) external _km_disable

0000000000001430 (__TEXT,__text) external _km_enable

0000000000000bd0 (__TEXT,__text) external _km_features

0000000000000780 (__TEXT,__text) external _km_find_devices

0000000000000970 (__TEXT,__text) external _km_find_devices_ext

0000000000001340 (__TEXT,__text) external _km_get_samplerate

0000000000001790 (__TEXT,__text) external _km_gpio_config_in

0000000000001830 (__TEXT,__text) external _km_gpio_config_out

0000000000001960 (__TEXT,__text) external _km_gpio_get

00000000000018d0 (__TEXT,__text) external _km_gpio_set

0000000000001030 (__TEXT,__text) external _km_latency

0000000000000a00 (__TEXT,__text) external _km_open

0000000000000a70 (__TEXT,__text) external _km_open_ext

0000000000000b60 (__TEXT,__text) external _km_port

0000000000000ea0 (__TEXT,__text) external _km_release

0000000000000db0 (__TEXT,__text) external _km_sleep_ms

0000000000000cb0 (__TEXT,__text) external _km_status_string

0000000000000f20 (__TEXT,__text) external _km_timeout

0000000000000c40 (__TEXT,__text) external _km_unique_id

0000000000000d30 (__TEXT,__text) external _km_version <--------------- MISSING FUNCTION IS HERE IN THE LIBRARY

(undefined) external _malloc (from libSystem)

(undefined) external _memset (from libSystem)

(undefined) external _open (from libSystem)

(undefined) external _strlen (from libSystem)

(undefined) external _strrchr (from libSystem)

(undefined) external dyld_stub_binder (from libSystem)




Any thoughts on what I am doing wrong? When I use nm on the .so I get a similar, but different, list.


The Mac OS X application is included in a workspace and references the project for the libkomodo.dylib (which is in the space workspace). The application includes libkomodo.dylib as a dependency.


Really appreaciate any assistance.

MacBook Pro, OS X Mavericks (10.9.1)

Posted on Apr 19, 2014 7:00 PM

Reply
1 reply

Use a shared object or dynamic library

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.