hedayat / powerfake

C++ Faking library, which allows faking/mocking regular functions, static member functions and non-virtual member functions for testing purposes.
Boost Software License 1.0
26 stars 1 forks source link

Need help with linker error #5

Open mbandu opened 8 months ago

mbandu commented 8 months ago

Hi, I am having this error when bind_fakes, couldn't figure out why...

bind_fakes(test_libcli_helper applib wrap_lib)

[ 67%] Generating test_libcli_helper.powerfake.link_flags, test_libcli_helper.powerfake.link_script objcopy: --redefine-sym: Symbol "__wrap_cli_loop" is target of more than one redefinition Exception: Running objcopy failed

Can anyone help me with this?

Regards,

Bandu

hedayat commented 8 months ago

Can you attach your test_libcli_helper.powerfake.link_flags, test_libcli_helper.powerfake.linkscript files? And make sure you don't have duplicate WRAP macros for a single function.

mbandu commented 8 months ago

Thank you so much for replying me. no duplicate on WARP_ macro.

test_libcli_helper.powerfake.link_script file is got 0 bytes empty. and test_libcli_helper.powerfake.link_flags is get deleted by make...

[ 65%] Built target bind_fakes_test_libcli_helper [ 67%] Generating test_libcli_helper.powerfake.link_flags, test_libcli_helper.powerfake.link_script objcopy: --redefine-sym: Symbol "__wrap_cli_done" is target of more than one redefinition Exception: Running objcopy failed

make[6]: [CMakeFiles/exec_bind_test_libcli_helper.dir/build.make:62: test_libcli_helper.powerfake.link_flags] Error 1 make[6]: Deleting file 'test_libcli_helper.powerfake.link_flags' make[5]: [CMakeFiles/Makefile2:112: CMakeFiles/exec_bind_test_libcli_helper.dir/all] Error 2 make[4]: [Makefile:84: all] Error 2 make[3]: [CMakeFiles/debug.dir/build.make:59: CMakeFiles/debug] Error 2 make[2]: [CMakeFiles/Makefile2:277: CMakeFiles/debug.dir/all] Error 2 make[1]: [CMakeFiles/Makefile2:284: CMakeFiles/debug.dir/rule] Error 2 make: [Makefile:196: debug] Error 2

‪On Sat, Mar 2, 2024 at 4:00 AM Hedayat Vatankhah (هدایت)‎ < @.***> wrote:‬

Can you attach your test_libcli_helper.powerfake.link_flags, test_libcli_helper.powerfake.linkscript files? And make sure you don't have duplicate WRAP macros for a single function.

— Reply to this email directly, view it on GitHub https://github.com/hedayat/powerfake/issues/5#issuecomment-1974736520, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWNO7CP7CU3FJKPHX6OJHTYWGIKVAVCNFSM6AAAAABECD3OFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZUG4ZTMNJSGA . You are receiving this because you authored the thread.Message ID: @.***>

-- Bandu @.***

mbandu commented 8 months ago

More inf: i use VERIFY, VERBOSE and STANDALONE flag for bind_fake

[ 68%] Linking CXX executable bind_fakes [ 68%] Built target bind_fakes [ 70%] Generating test_libcli_helper.powerfake.link_flags, test_libcli_helper.powerfake.link_script

Looking for marked functions in /mnt/d/WorkProjects/ManagedSwitchProject/bb-switch-cli/build/libwrap_lib.a

Found Prototype: PFKPrototypeStart: WRAPPED | cli_done | PowerFakeWrappfkalias8 | int ()(cli_def) | PFKPrototypeEnd Found Prototype: PFKPrototypeStart: WRAPPED | cli_loop | PowerFakeWrappfkalias6 | int ()(cli_def, int) | PFKPrototypeEnd

Looking for symbol names in /mnt/d/WorkProjects/ManagedSwitchProject/bb-switch-cli/build/libwrap_lib.a /mnt/d/WorkProjects/ManagedSwitchProject/bb-switch-cli/build/libapplib.a

Found symbol for int cli_loop(cli_def, int) == cli_loop (cli_loop) Found symbol for int cli_done(cli_def) == cli_done (cli_done) Found symbol for int cli_loop(cli_def, int) == cli_loop (cli_loop) Found symbol for int cli_done(cli_def) == cli_done (cli_done)

Match real symbols with our fake ones in /mnt/d/WorkProjects/ManagedSwitchProject/bb-switch-cli/build/libwrap_lib.a

Found wrapper symbol to rename/use: gcov0._ZN34wrapper_PowerFakeWrappfkalias6IPFiP7cli_defiEE49wrap_function_PowerFakeWrappfkalias6end__ES1_i gcov0._ZN34wrapper_PowerFakeWrappfkalias6IPFiP7cli_defiEE49wrap_function_PowerFakeWrappfkalias6endES1_i Found wrapper symbol to rename/use: gcov0._ZN34wrapper_PowerFakeWrappfkalias__8IPFiP7cli_defEE49wrap_functionPowerFakeWrappfkalias8endES1 gcov0._ZN34wrapper_PowerFakeWrappfkalias8IPFiP7cli_defEE49wrap_function_PowerFakeWrappfkalias8end_ES1 Found wrapper symbol to rename/use: gcov_._ZN34wrapper_PowerFakeWrappfkalias8IPFiP7cli_defEE49wrap_function_PowerFakeWrappfkalias8endES1_ _gcov._ZN34wrapper_PowerFakeWrappfkalias8IPFiP7cli_defEE49wrap_function_PowerFakeWrappfkalias8end_ES1 Found wrapper symbol to rename/use: gcov_._ZN34wrapper_PowerFakeWrappfkalias6IPFiP7cli_defiEE49wrap_function_PowerFakeWrappfkalias6endES1_i _gcov._ZN34wrapper_PowerFakeWrappfkalias6IPFiP7cli_defiEE49wrap_function_PowerFakeWrappfkalias6end__ES1_i Found wrapper symbol to rename/use: _ZN34wrapper_PowerFakeWrappfkalias6IPFiP7cli_defiEE49wrap_function_PowerFakeWrappfkalias6endES1_i wrapper_PowerFakeWrappfkalias__6<int ()(cli_def, int)>::wrap_function_PowerFakeWrappfkalias6end(cli_def, int) Found real symbol to rename: _Z49real_function_PowerFakeWrappfkalias6end__P7cli_defi real_function_PowerFakeWrappfkalias6end__(cli_def, int) Found wrapper symbol to rename/use: _ZN34wrapper_PowerFakeWrappfkalias8IPFiP7cli_defEE49wrap_function_PowerFakeWrappfkalias8endES1_ wrapper_PowerFakeWrappfkalias8<int ()(cli_def)>::wrap_function_PowerFakeWrappfkalias8end(cli_def*) Found real symbol to rename: _Z49real_function_PowerFakeWrappfkalias8endP7cli_def real_function_PowerFakeWrappfkalias8end(cli_def*) objcopy: --redefine-sym: Symbol "__wrap_cli_done" is target of more than one redefinition Exception: Running objcopy failed

make[2]: [CMakeFiles/exec_bind_test_libcli_helper.dir/build.make:62: test_libcli_helper.powerfake.link_flags] Error 1 make[2]: Deleting file 'test_libcli_helper.powerfake.link_flags' make[1]: [CMakeFiles/Makefile2:111: CMakeFiles/exec_bind_test_libcli_helper.dir/all] Error 2 make: [Makefile:84: all] Error 2

hedayat commented 8 months ago

It'd be nice if you can provide me with something with which I can reproduce the problem.

Also, maybe running make VERBOSE=1 provides me more info... although not sure if it'd be of much use without the content of test_libcli_helper.powerfake.link_flags file which is being deleted.

Removing ${link_flags_file} from add_custom_command output and add_custom_target depends in cmake/PowerFakeFunctions.cmake should prevent it from being removed.

hedayat commented 8 months ago

You might also try removing the STANDALONE flag to see if it has any effects.

mbandu commented 8 months ago

STANDALONE flag has no effects at all. Would ‘external “C”’ method be problem?

Thanks

Bandu @.***

On Mon, Mar 4, 2024 at 6:36 PM Hedayat Vatankhah (هدایت) < @.***> wrote:

You might also try removing the STANDALONE flag to see if it has any effects.

— Reply to this email directly, view it on GitHub https://github.com/hedayat/powerfake/issues/5#issuecomment-1977655326, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWNO7FVOOOFJWFMZVDWZFTYWUAQLAVCNFSM6AAAAABECD3OFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZXGY2TKMZSGY . You are receiving this because you authored the thread.Message ID: @.***>

mbandu commented 8 months ago

@hedayat thank you so much for your help. I found the issue. set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage") causing the issue. removing those code coverage compiler flags then successfully compile.

hedayat commented 8 months ago

Thanks for the info. I've tested with --coverage, so maybe the other flags are causing this problem. I'll look into it and hopefully fix it.

mbandu commented 8 months ago

Thanks again @hedayat . In my case, definitely --coverage is causing the issue. this doesn't help as I am writing unit test and can't see my code coverage. if you can find workaround would be super helpful.

mbandu commented 8 months ago

another clue is .. if just use -ftest-coverage .. no issue. -fprofile-arcs flag is also the issue. but i need both to see the report on the code coverage. :(