tags:

views:

104

answers:

1

Hello,

I have created a simple application that works ok. However, now I need to link with some libraries in the following directory.

/opt/norton/lib

In my make file I have the following with works, but I need to use cmake

LIBS_PATH = -L/opt/norton/lib
INC_PATH = -I/opt/norton/inc

LIBS = -lntctrl

In my CMakeList.txt I have this but doesn't work I keep gettng the following error:

undefined reference to `nt_init'

This is my CMakeList.txt

# Includes files
INCLUDE_DIRECTORIES(/opt/norton/inc)

# Link libraries
LINK_DIRECTORIES(/opt/norton/lib)

# Add the library that is used by nt_init
TARGET_LINK_LIBRARIES(-lntctrl)

ADD_LIBRARY(application initialize_nw)

Many thanks for any advice,

+3  A: 

Try out TARGET_LINK_LIBRARIES(ntctrl), the -l flag should not be used there (guess from what I have in mind)

This is how I would write the cmake file:

include_directories(/opt/norton/inc)
link_directories(/opt/norton/lib)
add_executable(application initialize_nw)
target_link_libraries(application ntctrl)

To show what are the actual command lines run during a make, use:

make VERBOSE=1

Maybe this shows you the difference between what you ran manually and the cmake generated commands.

jdehaan
Hello, thanks for the reply. Yes, I have actually tried that already (ntctrl). In my initilaize_nw.c I have included the header ntctrllib.h, so its including the header file as it doesn't show any error that it coudn't find it. Am I correct that TARGET_LINK_LIBRARIES is correct to use? Many thanks.
robUK
Hello, I am still having a problem when I specify the ntctrl library in the TARGET_LINK_LIBRARIES(ntctrl). The library is in the /opt/norton/lib directory. How does the TARGET_LINK... know that it need to search in the opt/norton/lib directory? Thanks.
robUK
LINK_DIRECTORIES is fine, maybe put the ADD_LIBRARY line before the TARGET_LINK_LIBRARIES, or even use ADD_EXECUTABLE instead (seems to me from the naming that application is not a lib)
jdehaan
Hello, I changed the ADD_LIBRARY before the TARGET_LINK_LIBRARIES. I had the same problem. However, if I compile on the command line like this: "gcc -I/opt/norton/include -L/opt/norton/lib -lntctrl initialize_nw -o application" I don't get any errors.
robUK
I edited the answer for better formatting (if that does not solve your issue, I am afraid I am then out of ideas), the name of the target shall be specified first when using target_link_libraries. I first thought it was positional by putting the target just before the links but I am quite sure now it is not: the name of the target must be specified.
jdehaan
Hello, thanks for your reply. However, I have followed this sample http://www.cmake.org/cmake/help/examples.html. But added my own source code in the Hello directory. The CMakeLists.txt in the Hello directory is what I am trying to change so that I can use the library ntctrl. I am all out of ideas now. There must be something I am doing wrong.
robUK
I made a check with my box (cmake 2.6 p4) works fine... I added a way to output the commands generated by cmake to help you find the difference between manual vs cmake command. I offer you to send me the files in a tar.gz so I can give it a try on exactly what you have.
jdehaan
Ok thanks, I have the tar files, just me know where you want me to email them?
robUK
Go to my profile -> my homepage -> impressum there you find my email (I don't want to post it here as I do not know how good it is obfuscated: these spammers drive me nuts ;-) )
jdehaan
Ok, I have sent you an email. Thanks.
robUK
I replied, but could actually find nothing useful. I simplified the files a bit and it works fine here. Curious to hear if it still fails for you.
jdehaan
Hello, I have just checked my inbox, no email from you. Can you confirm it was sent? Thanks.
robUK
I forwarded it a second time (the server is freenet and not color-of-code due to forwarding, maybe you have overseen it). The first time no error came back.
jdehaan
Now I got this error back: 52-5.7.0 Our system detected an illegal attachment on your message. Damned, I will send you the attachment as .txt (actually a tar.gz). you can rename and unpack it.
jdehaan