jmmut
jmmut

Reputation: 904

Can I hide my link flags from users of my conan package?

Let's say I have a library uploaded as a package in conan, which uses OpenGL, and as such links with GL in the CMakeLists.txt. Do the users of the library need to explicitly link against GL again? Does conan provide a method to track it and include it in ${CONAN_LIBS}?

The nearest thing I found in the docs is the method package_info, where it seems that you can specify linker extra options, but I don't seem to be using it properly in my library's conanfile.py. I tried all of:

    self.cpp_info.sharedlinkflags = ["-lGL", "GL", "libGL", "libGL.so", "-llibGL.so"] 

But if in the user code I don't put the link flag, it raises "undefined reference" to GL's methods.

EDIT: I'm working in linux mint 17.

Upvotes: 2

Views: 837

Answers (1)

drodri
drodri

Reputation: 5972

Yes, you need to declare it in the conanfile.py package_info() method, as conan decouples build (as defined in your cmake files) from package management. There is a specific attribute for libraries in the cpp_info attribute, which you could use:

def package_info(self):
    self.cpp_info.libs = ["GL"]

This libs field is transitive between dependencies, and the GL lib will be contained in the ${CONAN_LIBS} variable

The sharedlinkflags is transitive too, and it ends with its values accumulated in the cmake variable ${CMAKE_SHARED_LINKER_FLAGS}. But as its name states, it is only for shared linking, so it is likely that you are not building such a shared library, so your lib flags as GL are not being applied to your target.

Upvotes: 6

Related Questions