Ceedling icon indicating copy to clipboard operation
Ceedling copied to clipboard

How properly to link a libraries?

Open olyuboch opened this issue 6 years ago • 16 comments

Hello, I need to link my test project with -lpthread, in project.yml I had insert

:libraries: :placement: :end :flag: "-L ${1}" # or "-L ${1}" for example :common: &common_libraries [] :test: - -lpthread :release: - -lpthread

When I run it I get

Shell executed command: 'gcc "build/test/out/c/test_event_queue_runner.o" "build/test/out/c/test_event_queue.o" "build/test/out/c/unity.o" "build/test/out/c/my_event.o" "build/test/out/c/cmock.o" -o "build/test/out/test_event_queue.out"' And exited with status: [1]

And I didn't see there any libraries to link. What did I missed or where do I need to put -lpthread in .yml file?

System 4.15.0-34-generic #37~16.04.1-Ubuntu SMP Tue Aug 28 10:44:06 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux Ceedling:: 0.28.3 CMock:: 2.4.5 Unity:: 2.4.2 CException:: 1.3.1

olyuboch avatar Sep 27 '18 09:09 olyuboch

Thanks for bringing this up. It appears that this feature was started but never finished. I see code for the release library support, but none for tests.

For now, you can try to add these to your linker step directly.

Memo to myself or anyone who decides to tackle this issue:

  • It appears LIBRARY_TEST and LIBRARY_PLACEMENT are not used at all, thus far.
  • The docs don't really cover this feature yet
  • LIBRARY_SYSTEM is implemented, but also not documented
  • There are examples already in the starter yamls

mvandervoord avatar Sep 27 '18 10:09 mvandervoord

Oh... I see, thank you for an answer. I had been tried different ways from documentation and I found one which work in my case:

:tools: :test_compiler: :executable: gcc :arguments: - -Wall - -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE #expands to -I search paths - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR #expands to -I search paths - -D$: COLLECTION_DEFINES_TEST_AND_VENDOR #expands to all -D defined symbols - -c ${1} - -o ${2} :test_linker: :executable: gcc :arguments: - ${1} #list of object files to link (Ruby method call param list sub) - -lpthread - -o ${2} #executable file output (Ruby method call param list sub)

Not with :flags: either with :libraries: I can't to make it works, only with :tools:, so it is much more than enough for me.

olyuboch avatar Sep 27 '18 10:09 olyuboch

I'm glad the tools method is working for you. I'll try to get libraries fixed up soon for future use!

mvandervoord avatar Sep 27 '18 11:09 mvandervoord

Thanks, you do a great job)

olyuboch avatar Sep 27 '18 11:09 olyuboch

One more thing, when I use ceedling gcov:all the tools method with my flags for compiling and libraries for linking doesn't work. It looks like standard compiling settings are running in that moment, so I had to add flags -g -fprofile-arcs -ftest-coverage to my tools settings and then run gcov manualy on each function to look on coverage. Or maybe there is some way to set gcov method with tools method?

olyuboch avatar Sep 28 '18 09:09 olyuboch

Or maybe there is some way to set gcov method with tools method?

@olyuboch did you ever find a way to get ceedling gcov:all to work with :tools: configuration?

IvanRibakov avatar Jul 11 '19 07:07 IvanRibakov

Or maybe there is some way to set gcov method with tools method?

@olyuboch did you ever find a way to get ceedling gcov:all to work with :tools: configuration?

No I didn't)

olyuboch avatar Jul 11 '19 14:07 olyuboch

I have a project that uses libjanson and ceedling and gcov work just fine.

This is what needs to be done for gcov to work with it:

:tools_gcov_linker:
  :arguments:
    - -ljansson


dpostorivo avatar Jul 11 '19 14:07 dpostorivo

This is what needs to be done for gcov to work with it:

Thank you very much)

olyuboch avatar Jul 11 '19 15:07 olyuboch

Let me know if you still have issues.

dpostorivo avatar Jul 11 '19 15:07 dpostorivo

@kevlut are you running Ceedling v0.28.3? If so, consider building it from sources because #306 delivered some fixes to :libraries: config feature, but they haven't been released as part of an official release yet.

IvanRibakov avatar Aug 06 '19 21:08 IvanRibakov

@kevlut are you running Ceedling v0.28.3? If so, consider building it from sources because #306 delivered some fixes to :libraries: config feature, but they haven't been released as part of an official release yet.

@IvanRibakov scratch my previous comment--but I did also run into #306 along the way, so thanks for the heads up!

kevlut avatar Aug 06 '19 21:08 kevlut

Are there any plans to make a release yet? I'm running into this issue as well

utybo avatar Sep 29 '19 10:09 utybo

I'm not sure is this the correct way but I had to use -lm compiler switch to link the <math.h> into the test case and I did it with this

    :executable: gcc
    :arguments:
    - ${1} #list of object files to link (Ruby method call param list sub)
    - -o ${2} #executable file output (Ruby method call param list sub)
    - -lm```

tdarlic avatar Jan 15 '21 23:01 tdarlic

Hi there,

Thanks all for your inputs was very helpful for me, in order to summarize :

If you still have an issue with using pthread for ceedling and gcov please check the following yml configuration, it should solve your issue : (make sure to respect indentation very important !!!)

imageimage

To copy paste : < :libraries: :placement: :end :flag: "${1}" # or "-L ${1}" for example :common: &common_libraries [] :test: - *common_libraries :release: - *common_libraries

:tools: :test_compiler: :executable: gcc :arguments: - -Wall - -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE #expands to -I search paths - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR #expands to -I search paths - -D$: COLLECTION_DEFINES_TEST_AND_VENDOR #expands to all -D defined symbols - -c ${1} - -o ${2} :test_linker: :executable: gcc :arguments: - ${1} #list of object files to link (Ruby method call param list sub) - -lpthread - -o ${2} #executable file output (Ruby method call param list sub) :tools_gcov_linker: :arguments: - -lpthread

:plugins: :enabled: - stdout_pretty_tests_report - module_generator - gcov
- xml_tests_report
...

FYI :

image

SeifHadrich avatar Aug 12 '21 12:08 SeifHadrich

Save your time messing around with :tools:, instead use :libraries:. I added winmm under :test: like this:

:libraries:
  :placement: :end
  :flag: "-l${1}"
  :path_flag: "-L ${1}"
  :system: []    # for example, you might list 'm' to grab the math library
  :test: # []
    - winmm # my project needs this
  :release: []

sirdeniel avatar Apr 02 '23 03:04 sirdeniel