0

CMakeFiles/mqcreate.dir/mqcreate1.cc.o: In function main': mqcreate1.cc:(.text+0xa0): undefined reference tomq_open' mqcreate1.cc:(.text+0xad): undefined reference to `mq_close'

Eric lee
  • 23
  • 1
  • You need to link against the correct libraries to use these functions. Refer to `man mq_open` on Ubuntu. It should tell you which one to use. – fdk1342 May 24 '19 at 12:34

1 Answers1

2

Try this:

   find_library(LIBRT rt) 
   if(LIBRT)
      target_link_libraries(target_name ${LIBRT})
   endif()

link to the source

Bulat
  • 720
  • 7
  • 15
  • but I still confused that "add_compile_options(-lrt) " not work – Eric lee May 24 '19 at 14:46
  • @Ericlee Because it's not a compile option but a library used during linking. `find_library` is probably overkill and `target_link_libraries(target_name rt)` should suffice because it's a standard OS library that the linker can find on it's own. – fdk1342 May 25 '19 at 22:44