Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
POSIX GCC FreeRTOS compilation error
...
Finished building: ../AsyncIO/PosixMessageQueueIPC.c
Building target: FreeRTOS_Posix
Invoking: GCC C Linker
gcc -pthread -lrt -o"FreeRTOS_Posix" ./main.o ./ParTest/ParTest.o ./FreeRTOS_Kernel/croutine.o ./FreeRTOS_Kernel/list.o ./FreeRTOS_Kernel/queue.o ./FreeRTOS_Kernel/tasks.o ./FreeRTOS_Kernel/portable/MemMang/heap_3.o ./FreeRTOS_Kernel/portable/GCC/Posix/port.o ./FileIO/fileIO.o ./Common_Demo/Minimal/GenQTest.o ./Common_Demo/Minimal/QPeek.o ./Common_Demo/Minimal/blocktim.o ./Common_Demo/Minimal/countsem.o ./Common_Demo/Minimal/crflash.o ./Common_Demo/Minimal/crhook.o ./Common_Demo/Minimal/recmutex.o ./Common_Demo/Full/BlockQ.o ./Common_Demo/Full/PollQ.o ./Common_Demo/Full/death.o ./Common_Demo/Full/dynamic.o ./Common_Demo/Full/events.o ./Common_Demo/Full/flash.o ./Common_Demo/Full/flop.o ./Common_Demo/Full/integer.o ./Common_Demo/Full/print.o ./Common_Demo/Full/semtest.o ./AsyncIO/AsyncIO.o ./AsyncIO/AsyncIOSerial.o ./AsyncIO/AsyncIOSocket.o ./AsyncIO/PosixMessageQueueIPC.o
./AsyncIO/PosixMessageQueueIPC.o: In function `xPosixIPCOpen':
PosixMessageQueueIPC.c:(.text+0x25): undefined reference to `mq_open'
PosixMessageQueueIPC.c:(.text+0x106): undefined reference to `mq_notify'
PosixMessageQueueIPC.c:(.text+0x126): undefined reference to `mq_unlink'
./AsyncIO/PosixMessageQueueIPC.o: In function `vPosixIPCClose':
PosixMessageQueueIPC.c:(.text+0x185): undefined reference to `mq_close'
./AsyncIO/PosixMessageQueueIPC.o: In function `lPosixIPCSendMessage':
PosixMessageQueueIPC.c:(.text+0x1d4): undefined reference to `mq_send'
./AsyncIO/PosixMessageQueueIPC.o: In function `lPosixIPCReceiveMessage':
PosixMessageQueueIPC.c:(.text+0x218): undefined reference to `mq_receive'
./AsyncIO/PosixMessageQueueIPC.o: In function `prvPosixIPCInterruptHandler':
PosixMessageQueueIPC.c:(.text+0x394): undefined reference to `mq_notify'
./AsyncIO/PosixMessageQueueIPC.o: In function `vPosixIPCEmpty':
PosixMessageQueueIPC.c:(.text+0x442): undefined reference to `mq_receive'
./AsyncIO/PosixMessageQueueIPC.o: In function `vPosixIPCClose':
PosixMessageQueueIPC.c:(.text+0x193): undefined reference to `mq_unlink'
collect2: error: ld returned 1 exit status
make: *** [FreeRTOS_Posix] Error 1
@maks

This comment has been minimized.

Copy link

maks commented Nov 17, 2014

Hi not sure if you are still looking for an answer for this, but I ran into the very same issue and realised what was wrong thanks to (http://stackoverflow.com/questions/19964206/weird-posix-message-queue-linking-issue-sometimes-it-doesnt-link-correctly) , that the rt library needs to be at the end of the link step command line so on line 39 you want:
gcc -pthread -o"FreeRTOS_Posix" $(OBJS) $(USER_OBJS) $(LIBS) -lrt
note the "-lrt" is at the end of the line not beginning.

@pietv

This comment has been minimized.

Copy link

pietv commented Jun 18, 2016

@maks thanks! your advice helped me to build the thing.

@lv2eof

This comment has been minimized.

Copy link

lv2eof commented Jun 27, 2016

@maks What can I say besides what @pietv said?
Your advice also helped me.
I still have a lot of problems but I think that all of them are warnings.
But definitely the link error has disappeared :)

@giovanni-angeli

This comment has been minimized.

Copy link

giovanni-angeli commented May 9, 2017

@maks thanks! your advice helped me too!

@vivekverma

This comment has been minimized.

Copy link

vivekverma commented May 27, 2017

@maks I have chaged in the make file still I am getting same error

Please see the log
./AsyncIO/PosixMessageQueueIPC.o: In function xPosixIPCOpen': /home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:44: undefined reference to mq_open'
/home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:47: undefined reference to mq_unlink' /home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:85: undefined reference to mq_notify'
./AsyncIO/PosixMessageQueueIPC.o: In function vPosixIPCClose': /home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:96: undefined reference to mq_close'
/home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:99: undefined reference to mq_unlink' ./AsyncIO/PosixMessageQueueIPC.o: In function lPosixIPCSendMessage':
/home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:110: undefined reference to mq_send' ./AsyncIO/PosixMessageQueueIPC.o: In function lPosixIPCReceiveMessage':
/home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:131: undefined reference to mq_receive' ./AsyncIO/PosixMessageQueueIPC.o: In function vPosixIPCEmpty':
/home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:148: undefined reference to mq_receive' ./AsyncIO/PosixMessageQueueIPC.o: In function prvPosixIPCInterruptHandler':
/home/hackmachine_vivek/.local/share/Trash/files/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO

@vivekverma

This comment has been minimized.

Copy link

vivekverma commented May 27, 2017

@maks the make file is like this :-

################################################################################

Automatically-generated file. Do not edit!

################################################################################

-include ../makefile.init

RM := rm -rf

All of the sources participating in the build are defined here

-include sources.mk
-include subdir.mk
-include ParTest/subdir.mk
-include FreeRTOS_Kernel/subdir.mk
-include FreeRTOS_Kernel/portable/MemMang/subdir.mk
-include FreeRTOS_Kernel/portable/GCC/Posix/subdir.mk
-include FileIO/subdir.mk
-include Common_Demo/Minimal/subdir.mk
-include Common_Demo/Full/subdir.mk
-include AsyncIO/subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

-include ../makefile.defs

Add inputs and outputs from these tool invocations to the build variables

All Target

all: FreeRTOS_Posix

Tool invocations

FreeRTOS_Posix: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -pthread -o"FreeRTOS_Posix" $(OBJS) $(USER_OBJS) $(LIBS) -lrt
@echo 'Finished building target: $@'
@echo ' '

Other Targets

clean:
-$(RM) $(OBJS)$(C_DEPS)$(EXECUTABLES) FreeRTOS_Posix
-@echo ' '

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

@tyrelkostyk

This comment has been minimized.

Copy link

tyrelkostyk commented Jun 13, 2019

@vivekverma

Hi, I'm trying to run the Linux/POSIX FreeRTOS simulator on my Linux (running Ubunto Bionic Beaver 18.04), but can't seem to get it to work. I've made the exact changes you've proposed, within the FreeRTOS_POSIX/Release/makefile file. However the output is still the same:

Building target: FreeRTOS_Posix Invoking: GCC C Linker gcc -pthread -lrt -o "FreeRTOS_Posix" ./ParTest/ParTest.o ./FreeRTOS_Kernel/portable/MemMang/heap_3.o ./FreeRTOS_Kernel/portable/GCC/Posix/port.o ./FreeRTOS_Kernel/croutine.o ./FreeRTOS_Kernel/list.o ./FreeRTOS_Kernel/queue.o ./FreeRTOS_Kernel/tasks.o ./FileIO/fileIO.o ./Common_Demo/Minimal/GenQTest.o ./Common_Demo/Minimal/QPeek.o ./Common_Demo/Minimal/blocktim.o ./Common_Demo/Minimal/countsem.o ./Common_Demo/Minimal/crflash.o ./Common_Demo/Minimal/crhook.o ./Common_Demo/Minimal/recmutex.o ./Common_Demo/Full/BlockQ.o ./Common_Demo/Full/PollQ.o ./Common_Demo/Full/death.o ./Common_Demo/Full/dynamic.o ./Common_Demo/Full/events.o ./Common_Demo/Full/flash.o ./Common_Demo/Full/flop.o ./Common_Demo/Full/integer.o ./Common_Demo/Full/print.o ./Common_Demo/Full/semtest.o ./AsyncIO/AsyncIO.o ./AsyncIO/AsyncIOSerial.o ./AsyncIO/AsyncIOSocket.o ./AsyncIO/PosixMessageQueueIPC.o ./main.o ./AsyncIO/PosixMessageQueueIPC.o: In functionxPosixIPCOpen':
/home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:44: undefined reference to mq_open' makefile:37: recipe for target 'FreeRTOS_Posix' failed /home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:47: undefined reference to mq_unlink'
/home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:85: undefined reference to mq_notify' ./AsyncIO/PosixMessageQueueIPC.o: In function vPosixIPCClose':
/home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:96: undefined reference to mq_close' /home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:99: undefined reference to mq_unlink'
./AsyncIO/PosixMessageQueueIPC.o: In function lPosixIPCSendMessage': /home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:110: undefined reference to mq_send'
./AsyncIO/PosixMessageQueueIPC.o: In function lPosixIPCReceiveMessage': /home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:131: undefined reference to mq_receive'
./AsyncIO/PosixMessageQueueIPC.o: In function vPosixIPCEmpty': /home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:148: undefined reference to mq_receive'
./AsyncIO/PosixMessageQueueIPC.o: In function prvPosixIPCInterruptHandler': /home/tyrel/Documents/CubeSat/Software and Command/Software and Source Code/FreeRTOS/Posix_GCC_Simulator/FreeRTOS_Posix/Debug/../AsyncIO/PosixMessageQueueIPC.c:177: undefined reference to mq_notify'
collect2: error: ld returned 1 exit status
make: *** [FreeRTOS_Posix] Error 1
"make all" terminated with exit code 2. Build might be incomplete.

12:23:15 Build Failed. 11 errors, 5 warnings. (took 3s.329ms)
`

Just wondering if there's any other steps I should take? Thanks!!!

@tyrelkostyk

This comment has been minimized.

Copy link

tyrelkostyk commented Jun 13, 2019

Solved my Issue! For anyone else who has similar struggles:

The main problem was that I could modify the makefile (either in Debug/ or Release/ of the FreeRTOS_POSIX project), and it would build fine from the command line, but whenever I tried it from Eclipse it would fail and RESET that line 39 back to having -lrt where it was originally.

SO, you have to disable that setting in Eclipse: Go to Project > Properties > C/C++ Build > Builder Settings, and UNCHECK "Generate makefiles automatically"!

Hope this helps someone! Was a pain in the ass to figure out

@vivek-vermaa

This comment has been minimized.

Copy link

vivek-vermaa commented Apr 21, 2020

I faced this issue today . This is due to the linker error . I resolved it as follows :-

go to the make file of the project :-

to the tool invocation section of the makefile

the default linker command will be "gcc -pthread -lrt -o "FreeRTOS_Posix" $(OBJS) $(USER_OBJS) $(LIBS)"

replace it with "gcc -pthread -o"FreeRTOS_Posix" $(OBJS) $(USER_OBJS) $(LIBS) -lrt"

save the make file.

  1. Right click on the project and navigate to properties c/c++ build option .
  2. Uncheck Generate make files automatically .

If this option is enabled this will update the linker file automatically with gcc -pthread -o"FreeRTOS_Posix" $(OBJS) $(USER_OBJS) $(LIBS) -lrt .

so keep this option disabled .

compile and you are good to go .

@realtimepeople

This comment has been minimized.

Copy link

realtimepeople commented Jul 23, 2020

Even more simple:
Inside Eclipse, Go to C/C++Build/Settinhs/Tool Settings/GCCLInker/Miscellaneous/
and add
-lrt
into the "Other Objects" window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.