0

I am trying to link two static libraries to my application (libmc-lib.a and libmbed.a). I get a plethora of errors of undefined and duplicate symbols (see below the command line) although I followed the recommendation to put every object file before every other

$(GCC_ARM) $(LD_FLAGS) -T $(BINARY_NAME).link_script.ld $(LIBRARY_PATHS) --output $$@  $(LIBRARIES) $(src) $(LIBRARIES) $(src) $(LD_SYS_LIBS)

This expands to:

arm-none-eabi-gcc -Wl,--gc-sections -Wl,--wrap,main -Wl,--wrap,_malloc_r -Wl,--wrap,_free_r -Wl,--wrap,_realloc_r -Wl,--wrap,_memalign_r -Wl,--wrap,_calloc_r -Wl,--wrap,exit -Wl,--wrap,atexit -Wl,-n -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=softfp -DMBED_ROM_START=0x8000000 -DMBED_ROM_SIZE=0x200000 -DMBED_ROM1_START=0x200000 -DMBED_ROM1_SIZE=0x200000 -DMBED_BOOT_STACK_SIZE=1024  -T mcp.link_script.ld -Ltestdir/ --output output/mcp.elf  -lmbed -lmc-lib testdir/DW1000.o testdir/FsmClass.o testdir/FsmClass_sm.o testdir/MCCUwbCtrl.o testdir/MCLocationEngine.o testdir/MCSerial.o testdir/MCTwoWayRanging.o testdir/MyBuffer.o testdir/Ncp.o testdir/NcpApi.o testdir/NcpPower.o testdir/application.o testdir/colpin.o testdir/contactor.o testdir/controllogic.o testdir/device.o testdir/dotstar.o testdir/fsmtest.o testdir/main.o testdir/rowpin.o testdir/statusdisplay.o -lmbed -lmc-lib testdir/DW1000.o testdir/FsmClass.o testdir/FsmClass_sm.o testdir/MCCUwbCtrl.o testdir/MCLocationEngine.o testdir/MCSerial.o testdir/MCTwoWayRanging.o testdir/MyBuffer.o testdir/Ncp.o testdir/NcpApi.o testdir/NcpPower.o testdir/application.o testdir/colpin.o testdir/contactor.o testdir/controllogic.o testdir/device.o testdir/dotstar.o testdir/fsmtest.o testdir/main.o testdir/rowpin.o testdir/statusdisplay.o -Wl,--start-group -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys  -Wl,--end-group

This yields the totally overwhelming error messages (had to cut hundreds of messages due to length restrictions):

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/MCTwoWayRanging.o: in function `MCTwoWayRanging::sendPositionAnnounceFrame(MCSerial::DeviceId const&, MCSerial::DeviceId const&, float const&, float const&)':
mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:505: multiple definition of `MCTwoWayRanging::sendPositionAnnounceFrame(MCSerial::DeviceId const&, MCSerial::DeviceId const&, float const&, float const&)'; testdir/MCTwoWayRanging.o:mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:505: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/MCTwoWayRanging.o: in function `MCTwoWayRanging::sendIEEEFrame(unsigned long long)':

mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:572: multiple definition of `MCTwoWayRanging::sendIEEEFrame(unsigned long long)'; testdir/MCTwoWayRanging.o:mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:572: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/MCTwoWayRanging.o: in function `MCTwoWayRanging::setAddress(unsigned long)':
mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:584: multiple definition of `MCTwoWayRanging::setAddress(unsigned long)'; testdir/MCTwoWayRanging.o:mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:584: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/MCTwoWayRanging.o: in function `MCTwoWayRanging::setAntennaDelay(unsigned short)':
mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:589: multiple definition of `MCTwoWayRanging::setAntennaDelay(unsigned short)'; testdir/MCTwoWayRanging.o:mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:589: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/MCTwoWayRanging.o: in function `MCTwoWayRanging::getAntennaDelay()':
mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:619: multiple definition of `MCTwoWayRanging::getAntennaDelay()'; testdir/MCTwoWayRanging.o:mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:619: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/MCTwoWayRanging.o: in function `MCTwoWayRanging::getLastAnnouncementframe(RangingAnnounceFrame&)':
mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:623: multiple definition of `MCTwoWayRanging::getLastAnnouncementframe(RangingAnnounceFrame&)'; testdir/MCTwoWayRanging.o:mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:623: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/MCTwoWayRanging.o: in function `MCTwoWayRanging::printTimingInformation()':
mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:635: multiple definition of `MCTwoWayRanging::printTimingInformation()'; testdir/MCTwoWayRanging.o:mcp-cpu/uwb_ranging/src/MCTwoWayRanging.cpp:635: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::Ncp(PinName, PinName, PinName, mc::baudrate)':
mcp-cpu/src/Ncp/Ncp.cpp:4: multiple definition of `Ncp::Ncp(PinName, PinName, PinName, mc::baudrate)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:4: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o:(.rodata._ZTV3Ncp+0x0): multiple definition of `vtable for Ncp'; testdir/Ncp.o:(.rodata._ZTV3Ncp+0x0): first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::Ncp(PinName, PinName, PinName, mc::baudrate)':
mcp-cpu/src/Ncp/Ncp.cpp:4: multiple definition of `Ncp::Ncp(PinName, PinName, PinName, mc::baudrate)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:4: first defined here
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::turnOn()':
mcp-cpu/src/Ncp/Ncp.cpp:42: multiple definition of `Ncp::turnOn()'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:42: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::turnOff()':

mcp-cpu/src/Ncp/Ncp.cpp:46: multiple definition of `Ncp::turnOff()'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:46: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::setEventHandler(mc::function<void (NcpApiEvent, void*), 12, 4>)':

mcp-cpu/src/Ncp/Ncp.cpp:53: multiple definition of `Ncp::setEventHandler(mc::function<void (NcpApiEvent, void*), 12, 4>)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:53: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::isReady()':

mcp-cpu/src/Ncp/Ncp.cpp:57: multiple definition of `Ncp::isReady()'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:57: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::waitUntilReadyFor(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)':

mcp-cpu/src/Ncp/Ncp.cpp:61: multiple definition of `Ncp::waitUntilReadyFor(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:61: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::echo(int, std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)':

mcp-cpu/src/Ncp/Ncp.cpp:65: multiple definition of `Ncp::echo(int, std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:65: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::setSessionCounter(unsigned long, std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)':

mcp-cpu/src/Ncp/Ncp.cpp:69: multiple definition of `Ncp::setSessionCounter(unsigned long, std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:69: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::mcc_setRequestHandler(mc::function<void (mc::mcp_command), 12, 4>)':

mcp-cpu/src/Ncp/Ncp.cpp:73: multiple definition of `Ncp::mcc_setRequestHandler(mc::function<void (mc::mcp_command), 12, 4>)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:73: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::mcc_listen(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)':

mcp-cpu/src/Ncp/Ncp.cpp:77: multiple definition of `Ncp::mcc_listen(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:77: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::mcc_unlisten(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)':

mcp-cpu/src/Ncp/Ncp.cpp:81: multiple definition of `Ncp::mcc_unlisten(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'; testdir/Ncp.o:mcp-cpu/src/Ncp/Ncp.cpp:81: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/Ncp.o: in function `Ncp::mcc_respond(mc::mcp_state)':

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/application.o: in function `Application::Application()':

mcp-cpu/src/device.cpp:635: multiple definition of `Device::testEthernet()'; testdir/device.o:mcp-cpu/src/device.cpp:635: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/device.o: in function `Device::testOscillator()':

mcp-cpu/src/device.cpp:648: multiple definition of `Device::testOscillator()'; testdir/device.o:mcp-cpu/src/device.cpp:648: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/device.o: in function `Device::testSearchContact()':

mcp-cpu/src/device.cpp:728: multiple definition of `Device::testSearchContact()'; testdir/device.o:mcp-cpu/src/device.cpp:728: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/device.o: in function `Device::testRelays()':

mcp-cpu/src/device.cpp:733: multiple definition of `Device::testRelays()'; testdir/device.o:mcp-cpu/src/device.cpp:733: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/device.o: in function `Device::resetContactReady()':

mcp-cpu/src/device.cpp:738: multiple definition of `Device::resetContactReady()'; testdir/device.o:mcp-cpu/src/device.cpp:738: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/device.o: in function `Device::startCharging()':

mcp-cpu/src/device.cpp:743: multiple definition of `Device::startCharging()'; testdir/device.o:mcp-cpu/src/device.cpp:743: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/device.o: in function `Device::stopCharging()':

mcp-cpu/src/device.cpp:754: multiple definition of `Device::stopCharging()'; testdir/device.o:mcp-cpu/src/device.cpp:754: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/dotstar.o: in function `std::_Vector_base<LED, std::allocator<LED> >::_M_allocate(unsigned int)':

c:\program files (x86)\gnu tools arm embedded\9 2019-q4-major\arm-none-eabi\include\c++\9.2.1\bits/vector.tcc:617: multiple definition of `Dotstar::Dotstar(mbed::SPI*, int)'; testdir/dotstar.o:mcp-cpu/dotstar/dotstar.cpp:3: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/dotstar.o: in function `std::_Vector_base<LED, std::allocator<LED> >::_M_allocate(unsigned int)':

c:\program files (x86)\gnu tools arm embedded\9 2019-q4-major\arm-none-eabi\include\c++\9.2.1\bits/vector.tcc:617: multiple definition of `Dotstar::Dotstar(mbed::SPI*, int)'; testdir/dotstar.o:mcp-cpu/dotstar/dotstar.cpp:3: first defined here

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/dotstar.o: in function `Dotstar::update()':

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/NcpApi.o: in function `_Z...[lots of C++ name mangling characters removed]':

mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:213: undefined reference to `mc::mutex::lock()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:226: undefined reference to `mc::semaphore::release()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:228: undefined reference to `mc::mutex::unlock()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/NcpApi.o: in function `_Z...[lots of C++ name mangling characters removed]':

mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:213: undefined reference to `mc::mutex::lock()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:226: undefined reference to `mc::semaphore::release()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:228: undefined reference to `mc::mutex::unlock()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/NcpApi.o: in function `_Z...[lots of C++ name mangling characters removed]':

mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:213: undefined reference to `mc::mutex::lock()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mcp-cpu/mc-lib/include/mc/rpc/controller.hpp:226: undefined reference to `mc::semaphore::release()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/NcpApi.o: in function `_Z...[lots of C++ name mangling characters removed]':

mcp-cpu/mc-lib/include/mc/rtos/platform/mbed_os/thread.hpp:33: undefined reference to `mc::thread::run()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/NcpApi.o: in function `void mc::spsc_queue<std::byte, -1>::push<std::byte, void>(std::byte&&)':

mcp-cpu/mc-lib/include/mc/rtos/queue/spsc_queue.hpp:111: undefined reference to `mc::semaphore::acquire()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mcp-cpu/mc-lib/include/mc/rtos/queue/spsc_queue.hpp:114: undefined reference to `mc::semaphore::release()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/NcpApi.o: in function `mc::spsc_queue<std::byte, -1>::pop()::{lambda()#1}::operator()() const':

mcp-cpu/mc-lib/include/mc/rtos/queue/spsc_queue.hpp:156: undefined reference to `mc::semaphore::release()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/NcpApi.o: in function `mc::spsc_queue<std::byte, -1>::pop()':

mcp-cpu/mc-lib/include/mc/rtos/queue/spsc_queue.hpp:151: undefined reference to `mc::semaphore::acquire()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/application.o: in function `Application::Application()':

mcp-cpu/src/application.cpp:156: undefined reference to `mc::this_thread::sleep_for(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mcp-cpu/src/application.cpp:171: undefined reference to `mc::this_thread::sleep_for(std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/\libmc-lib.a(mutex_lock.o): in function `mc::mutex_lock::mutex_lock(mc::mutex&)':

mcp-cpu/mc-lib/src/rtos/mutex_lock.cpp:7: undefined reference to `mc::mutex::lock()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: testdir/\libmc-lib.a(mutex_lock.o): in function `mc::mutex_lock::~mutex_lock()':

mcp-cpu/mc-lib/src/rtos/mutex_lock.cpp:11: undefined reference to `mc::mutex::unlock()'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-fclose.o): in function `_fclose_r':

fclose.c:(.text._fclose_r+0x50): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: fclose.c:(.text._fclose_r+0x5e): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: fclose.c:(.text._fclose_r+0xbe): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-fflush.o): in function `__sflush_r':

fflush.c:(.text.__sflush_r+0x94): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-fread.o): in function `_fread_r':

fread.c:(.text._fread_r+0xfa): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-fseeko.o):fseeko.c:(.text._fseeko_r+0xbc): more undefined references to `__wrap__free_r' follow

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-makebuf.o): in function `__smakebuf_r':

makebuf.c:(.text.__smakebuf_r+0x2c): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-malloc.o): in function `malloc':

malloc.c:(.text.malloc+0x6): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-malloc.o): in function `free':

malloc.c:(.text.free+0x6): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-realloc.o): in function `realloc':

realloc.c:(.text.realloc+0x8): undefined reference to `__wrap__realloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-refill.o): in function `__srefill_r':

refill.c:(.text.__srefill_r+0x7c): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-svfprintf.o): in function `_svfprintf_r':

vfprintf.c:(.text._svfprintf_r+0x30c): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfprintf.c:(.text._svfprintf_r+0x868): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfprintf.c:(.text._svfprintf_r+0xeea): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfprintf.c:(.text._svfprintf_r+0x173e): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-tzset_r.o): in function `_tzset_unlocked_r':

tzset_r.c:(.text._tzset_unlocked_r+0x40): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-ungetc.o): in function `__submore':

ungetc.c:(.text.__submore+0x16): undefined reference to `__wrap__realloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: ungetc.c:(.text.__submore+0x3e): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-vfprintf.o): in function `_vfprintf_r':

vfprintf.c:(.text._vfprintf_r+0x39c): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfprintf.c:(.text._vfprintf_r+0x8ee): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfprintf.c:(.text._vfprintf_r+0x1816): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-wsetup.o): in function `__swsetup_r':

wsetup.c:(.text.__swsetup_r+0xa2): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-fvwrite.o): in function `__sfvwrite_r':

fvwrite.c:(.text.__sfvwrite_r+0x26c): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: fvwrite.c:(.text.__sfvwrite_r+0x2a2): undefined reference to `__wrap__realloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: fvwrite.c:(.text.__sfvwrite_r+0x2b0): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-mprec.o): in function `_Balloc':

mprec.c:(.text._Balloc+0x22): undefined reference to `__wrap__calloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: mprec.c:(.text._Balloc+0x3e): undefined reference to `__wrap__calloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-svfiprintf.o): in function `__ssprint_r':

vfprintf.c:(.text.__ssprint_r+0x4e): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfprintf.c:(.text.__ssprint_r+0xbc): undefined reference to `__wrap__realloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfprintf.c:(.text.__ssprint_r+0xca): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-svfiprintf.o): in function `_svfiprintf_r':

vfprintf.c:(.text._svfiprintf_r+0xa40): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-svfiscanf.o): in function `__ssrefill_r':

vfscanf.c:(.text.__ssrefill_r+0x10): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/softfp\libc.a(lib_a-svfwprintf.o): in function `_svfwprintf_r':

vfwprintf.c:(.text._svfwprintf_r+0x33e): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfwprintf.c:(.text._svfwprintf_r+0x870): undefined reference to `__wrap__free_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfwprintf.c:(.text._svfwprintf_r+0xf16): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfwprintf.c:(.text._svfwprintf_r+0x1526): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfwprintf.c:(.text._svfwprintf_r+0x1656): undefined reference to `__wrap__malloc_r'

c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/arm-none-eabi/bin/ld.exe: vfwprintf.c:(.text._svfwprintf_r+0x166c): undefined reference to `__wrap__malloc_r'

collect2.exe: error: ld returned 1 exit status
make[1]: *** [/cygdrive/c/Users/mark.piffer/code/mcp/mcp-cpu/buildsys/steptemplate.mk:669: output/mcp-cpu_gamma2_V0.1-2-gfef3f020-dirty_MarkPiffer_CYGWIN_NT-10.0_MPIFFER_20211203.141933-NPR7.elf] Error 1
make: *** [buildsys/makefile:279: ~do7] Error 1

I am rather lost on what goes wrong here. I followed the recommendation from here: Why does the order in which libraries are linked sometimes cause errors in GCC? to name the possible circular dependencies twice as you see (the -( -) parenthesizing throws an error, in all possible escaping sequences) but to no avail. What are the proper tools to query the libraries for the purportedly missing or duplicate symbols?

Also, the missing __wrap__... symbols (see last few errors) are puzzling, as there are provably the correct functions in there:

$ grep -r --include=*.c* -e __wrap__malloc_r mbed-os
mbed-os/platform/mbed_alloc_wrappers.cpp:extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size)

$ ar tv testdir/libmbed.a | grep mbed_alloc_wrappers
rw-rw-rw- 0/0 1794944 Dec  2 22:24 2021 mbed_alloc_wrappers.o
Vroomfondel
  • 2,704
  • 1
  • 15
  • 29
  • The multiple definition errors occur since the object file names are repeated in the link command so the linker will try to link two copies of each symbol into the executable. Also be sure to put the libraries after the object files or the linker will complain about undefined symbols – xnsc Dec 04 '21 at 00:31
  • @xnsc the first answer in the question I linked claims differently, you can purportedly name a lib two times in the command line? – Vroomfondel Dec 04 '21 at 10:12
  • Yes, you can name libraries (.a, .so) multiple times but not object file names (.o). These should only be named once and they should go before any libraries. – xnsc Dec 04 '21 at 17:24
  • @xnsc Ah, ok, you are right of course. Thing is, I tried various combinations, then read the extremely valuable https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking and tried some more, without duplicate object files. The problems persist. I also tried w/o self written libs (only object files) and a similar result. I think now the problem comes in at the compile step by a funny aliasing problem which I havent pinned down yet. – Vroomfondel Dec 05 '21 at 11:38

0 Answers0