[CMake] cmake linking errors in simple project

Raymond Wan rwan.work at gmail.com
Mon Jul 6 03:53:36 EDT 2015


Hi Owen,


On Mon, Jul 6, 2015 at 3:48 PM, Owen Alanzo Hogarth <gurenchan at gmail.com> wrote:
> I created this simple project but I am having linking errors. Everything
> builds correctly but when I try to add my lib to my main.c cmake complains
> about linking errors.
>
> Here's what the project looks like: http://pastebin.com/22bCsuiE
>
> if i #include "time_utils.h" in my main.c I get this error:
>
> Scanning dependencies of target launcher
> [ 50%] Building C object CMakeFiles/launcher.dir/main.c.o
> /Users/xx/project/main.c:2:10: fatal error: 'time_utils.h' file not found
> #include "time_utils.h"
>
> if I remove that line from the main.c it builds properly. I though adding
> this line TARGET_LINK_LIBRARIES(auncher time_utils) to my cmakelists.txt it
> would find the library but seems not. How can I make sure that the library
> is found and properly linked?


Perhaps you can try adding:

INCLUDE_DIRECTORIES (<path to where time_utils.h is>)

It looks like the problem is with compiling main.c.  That's when it is
looking for the header files.  It isn't linking yet.  That is what
TARGET_LINK_LIBRARIES is for.

Not sure if this is the right solution, but maybe you can give it a
try; that is what I'm doing.

Ray


More information about the CMake mailing list