Question

I am getting a link error on the Mac build of my FireBreath plugin looking like this:

Undefined symbols for architecture x86_64:
  "_IOIteratorNext", referenced from:
      MyFunction(...) in MyFile.o

Please help me solve this link error.

I have similar errors for "_IOObjectRelease", "_IORegistryEntryCreateCFProperty", "_IORegistryEntryGetParentEntry", "_IOServiceGetMatchingServices", "_IOServiceMatching", and "_kIOMasterPortDefault". This leads me to believe that I need to include the Frameworks IOKIT and COREFOUNDATION.

I have concluded that these are the Frameworks that I need because I can temporarily get the build to succeed by adding them directly to Xcode like this:

  1. In the project navigator select the project.
  2. Select the target.
  3. Select the 'Build Phases' tab.
  4. Open 'Link Binaries With Libraries' expander (You may have to use 'Add Build Phase').
  5. Click the '+' button once to add each of the Frameworks.

After adding the Frameworks through Xcode, the build succeeds. However, once the prep script 'prepmac.sh' is run again, the Frameworks are lost and the build fails.

I have tried adding the Frameworks through FireBreath in several ways by editing PluginConfig.cmake and Mac/projectDef.cmake, and even considered modifying CMakeLists.txt, but this seems less promising.

I have tried the following statements in various combinations within the two .cmake files, but I am not confident about where to put them:

find_library(IOKIT_FRAMEWORK IOKit)
message("Finding library IOKit: ${IOKIT_FRAMEWORK}")

find_library(COREFOUNDATION_FRAMEWORK CoreFoundation)
message("Finding library CoreFoundation: ${COREFOUNDATION_FRAMEWORK}")

target_link_libraries(${PROJECT_NAME}
    ${COREFOUNDATION_FRAMEWORK}
    ${IOKIT_FRAMEWORK}
    ${PLUGIN_INTERNAL_DEPS}
)

None of the changes seem to change the build log. Of course I am generating the project between changes with "prepmac.sh", in which the new 'message' statements report:

Finding library IOKit: /System/Library/Frameworks/Cocoa.framework
Finding library CoreFoundation: /System/Library/Frameworks/CoreFoundation.framework

Solution: Based on advice from taxilian the solution was both to correctly specify the correct Frameworks in Mac/projectDef.cmake and completely delete the build directory and remake it from scratch with the prepmac.sh script.

Was it helpful?

Solution

Simply doing a find_library is not enough to make it link; you need to add it to a target_link_libraries call as well. Also you should really make sure that your case matches the libraries themselves; I don't know if that matters or not on mac, but it's good practice in case it's a case sensitive filesystem (and yes that's possible to have on mac).

The correct case for the frameworks is "IOKit" and "CoreFoundation"

You can find more information on how to do this correctly on the Using Libraries page on firebreath.org. Try something like this:

find_library(IOKIT_FRAMEWORK IOKit)
find_library(COREFOUNDATION_FRAMEWORK CoreFoundation)
target_link_libraries(${PROJECT_NAME} ${COREFOUNDATION_FRAMEWORK} ${IOKIT_FRAMEWORK})

Note that this needs to be in your Mac/projectDef.cmake file somewhere after the "add_mac_plugin" call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top