Conan: [bug] The SCons generator doesn't export system_libs

Created on 2 Jul 2020  ·  4Comments  ·  Source: conan-io/conan

As a bit of background, I recently had a very strange issue with icu/67.1. Specifically, when I built the release build, it produced linking errors. The debug build was strangely fine, but this turned out to be random.

A few rabbit holes and a few hours later, I managed to figure out why -- I wasn't linking against -ldl and -lpthread. Linking against only -ldl didn't cause link errors, but it caused System error: -1 (or something along the lines of that) at runtime.

I decided to run the linker into verbose mode, and noticed several libraries were missing. I cross-referenced with the recipe, and in the debug build, the flags weren't present. I checked the SConscript file generated several times, but the last time around I noticed that there was no -pthread or -ldl. I also just confirmed these two were only included because of my use of sanitizers - it working this far has been pure luck.

Finally, the problem itself, and the reason I'm opening this issue here, is that the SCons generator doesn't export system_libs. That's why it fails to link or run.

Environment Details (include every applicable attribute)

  • Operating System+version: Linux Mint 19.3
  • Compiler+version: Clang 10
  • Conan version: 1.27.0
  • Python version: 3.8.0

Steps to reproduce (Include if Applicable)

conanfile.py:

from conans import ConanFile

class Taskranger(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "ycm", "scons"

    default_options = {
        "icu:data_packaging": "static",
        "icu:shared": False
    }

    def requirements(self):
        self.requires("icu/67.1")

main.cpp:

#include "unicode/smpdtfmt.h"

int main() {
    using namespace icu;
    UErrorCode status = U_ZERO_ERROR;
    SimpleDateFormat sdf(UnicodeString("dd.MM.y"), status);
}

SConstruct:

env = Environment(CXXFLAGS="-std=c++17")
flags = SConscript("build/SConscript_conan")
env.MergeFlags(flags["conan"])
print(flags)
env.Program("demo", "main.cpp")

Commands after placing the files above in a directory:

mkdir build
cd build
conan install .. --build missing
scons ..

... and watch the compiler come up with undefined references to -ldl stuff. With with_dyload: False, it will compile, but it throws an std::system_error because pthreads isn't linked. Both of these are defined as system_libs, neither are included in the flags generated by the SCons generator. This should in theory, in a simple enough environment, happen to any and all packages using system_libs.

Output with:

Default settings:

g++ -o main.o -c -std=c++17 -DU_STATIC_IMPLEMENTATION -I/home/lunarwatcher/.conan/data/icu/67.1/_/_/package/b840526c6db636afcf60cda7b7728f7e08d6bb6e/include main.cpp
g++ -o demo main.o -L/home/lunarwatcher/.conan/data/icu/67.1/_/_/package/b840526c6db636afcf60cda7b7728f7e08d6bb6e/lib -licui18n -licuio -licutest -licutu -licuuc -licudata
/home/lunarwatcher/.conan/data/icu/67.1/_/_/package/b840526c6db636afcf60cda7b7728f7e08d6bb6e/lib/libicuuc.a(putil.ao): In function `uprv_dl_open_67':
putil.cpp:(.text.uprv_dl_open_67+0x13): undefined reference to `dlopen'
/home/lunarwatcher/.conan/data/icu/67.1/_/_/package/b840526c6db636afcf60cda7b7728f7e08d6bb6e/lib/libicuuc.a(putil.ao): In function `uprv_dl_close_67':
putil.cpp:(.text.uprv_dl_close_67+0x7): undefined reference to `dlclose'
/home/lunarwatcher/.conan/data/icu/67.1/_/_/package/b840526c6db636afcf60cda7b7728f7e08d6bb6e/lib/libicuuc.a(putil.ao): In function `uprv_dlsym_func_67':
putil.cpp:(.text.uprv_dlsym_func_67+0xe): undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
scons: *** [demo] Error 1
scons: building terminated because of errors.

with_dyload: False:

❯ ./demo
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
[1]    6878 abort (core dumped)  ./demo
bug

Most helpful comment

Merged to develop, will be in Conan 1.28. It is now available in PyPI test: https://test.pypi.org/project/conan

All 4 comments

Hi @LunarWatcher

Thanks very much for your detailed report, very appreciated.

Indeed a bug, system_libs was introduced recently, it was apparently implemented in all generators but scons. As SCons is not that common nowadays, this bug passed unnoticed.

I have submitted a fix in https://github.com/conan-io/conan/pull/7302, scheduled for next release. As an SCons user, it would be great if you could have a look (maybe even trying running from source from my branch?) to the PR and give feedback. Thanks!

Just ran it against my actual project, as well as the test code I included here, and it does properly include all the system_libs now. Also checked against 3 additional libraries (just checking the flags though), and all of the relevant system libraries seem to be included in the flags, so it looks good to me.

That being said, and I have no way to test this because I don't have a Mac, but does the generator factor in frameworks? Not sure if that's necessary at all though. 🤷‍♀️

And thank you for working on it!

That was a quick check, great :)

Good point about the frameworks. That is right, the generator is not handling the frameworks either, exactly same issue as system_libs, also for the same reasons.

I don't have a Mac, neither I know much about SCons, but I have contributed them based on https://scons.org/doc/production/HTML/scons-man.html documentation, in same PR: https://github.com/conan-io/conan/pull/7302/commits/6a5a8081693c9b3d5422eb1a8ddf2818f7a8794d

Merged to develop, will be in Conan 1.28. It is now available in PyPI test: https://test.pypi.org/project/conan

Was this page helpful?
0 / 5 - 0 ratings