Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

linker issues when building a standalone plugin + fix suggestion

Open
#10 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c, cmake
Domain
build-system

Research direction

Start with the standalone sample output plugin build steps in README and the FLB_PLUGIN macro shown in the issue. Reproduce the macOS arm64 linker failure, then compare the proposed platform-specific link options with the existing macro. Done means the standalone plugin builds successfully without undefined-symbol errors on the supported platforms.

Written by the indexing model from the issue text.

Description

Hi,

I followed the steps in the README to compile the sample output plugin as standalone.

As suggested i have cloned the fluent-bit source code from current master, and have the cmake command point to it through FLB_SOURCE

I did not test using header packages either, since there is this open issue that i also faced:
https://github.com/fluent/fluent-bit/issues/7028

I also had to follow this comment and run cmake to have autogenerated files working:
https://github.com/fluent/fluent-bit-plugin/issues/2#issuecomment-520614809

So far i could only test this on MacOS, and I still have the following error:

[100%] Linking C shared library ../flb-out_stdout2.dylib
Undefined symbols for architecture arm64:
  "_co_switch", referenced from:
      _flb_output_return_do in stdout2.c.o
  "_flb_coro_get", referenced from:
      _flb_output_return_do in stdout2.c.o
  "_flb_errno_print", referenced from:
      _flb_output_return in stdout2.c.o
  "_flb_event_chunk_destroy", referenced from:
      _flb_output_return in stdout2.c.o
  "_flb_output_flush_prepare_destroy", referenced from:
      _flb_output_return in stdout2.c.o
  "_flb_output_thread_instance_get", referenced from:
      _flb_output_return in stdout2.c.o
  "_flb_pack_print", referenced from:
      _cb_stdout_flush in stdout2.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [flb-out_stdout2.dylib] Error 1
make[1]: *** [out_stdout2/CMakeFiles/flb-out_stdout2.dir/all] Error 2
make: *** [all] Error 2

A fix that worked for me was to update the FLB_PLUGIN_MACRO with code borrowed from here:
https://github.com/icn-team/cmake-modules/blob/a7b8a8e60fb4b4d35df628003f1d80438736603b/Modules/BuildMacros.cmake#L334

The working macro:

macro(FLB_PLUGIN name src deps)
  add_library(flb-${name} SHARED ${src})
  set_target_properties(flb-${name} PROPERTIES PREFIX "")
  set_target_properties(flb-${name} PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

  if (${CMAKE_SYSTEM_NAME} MATCHES Darwin)
    list(APPEND ARG_LINK_FLAGS "-Wl,-undefined,dynamic_lookup")
  elseif(${CMAKE_SYSTEM_NAME} MATCHES iOS)
    list(APPEND ARG_LINK_FLAGS "-Wl,-undefined,dynamic_lookup")
  elseif(${CMAKE_SYSTEM_NAME} MATCHES Linux)
    list(APPEND ARG_LINK_FLAGS "-Wl,-unresolved-symbols=ignore-all")
  elseif(${CMAKE_SYSTEM_NAME} MATCHES Windows)
    list(APPEND ARG_LINK_FLAGS "/wd4275")
  else()
    message(FATAL_ERROR "Trying to build module on a not supportd platform. Aborting.")
  endif()
  target_link_options(flb-${name} PRIVATE ${ARG_LINK_FLAGS})

  target_link_libraries(flb-${name} ${deps})
endmacro()

Note that depending on the target cmake version, there is also the possibility to pass the flags as the second parameter of FLB_PLUGIN, which passes it to target_link_libraries, as documented here: https://cmake.org/cmake/help/latest/command/target_link_libraries.html

What are your opinions on this ? Thanks in advance.

🙌 Thanks to Mauro for suggesting the fix

Dominant language
C
Stars
14
Forks
12
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fluent/fluent-bit-plugin

All issues in fluent/fluent-bit-plugin

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.