[QBS] Wrong ld arguments depending on source files

Ilya Lyubimov villytiger at gmail.com
Tue Apr 7 14:55:10 CEST 2015


2015-04-07 12:53 GMT+03:00 Joerg Bornemann <joerg.bornemann at theqtcompany.com>:
> On 04-Apr-15 10:39, Ilya Lyubimov wrote:
>
>> I have a directory called crypto in my project. At the same time I
>> want to link my product with crypto library. The problem is that
>> linkerFlags function from gcc.js looks for file with library name and
>> having found crypto directory (I think it would be wrong behaviour
>> even if crypto was a regular file) it doesn't pass "-l" argument. So
>> in this situation the only option is to pass linkerFlags manually.
>> I think a possible solution for this issue would be to split
>> staticLibraries and dynamicLibraries properties into properties for
>> libraries by name and properties for libraries by path, or use ":"
>> prefix, as ld with "-l" argument do, for passing libraries by path.
>
> How would those pairs of properties be called?

For example, staticLibraryFiles and dynamicLibraryFiles, from which
qbs would try to find corresponding files on file system or pass them
with ":" prefix to ld. Then current properties, staticLibraries and
dyanmicLibraries, would contain only library names.

>
> Why is "crypto" found by ld anyways? Did you add the project directory
> to the linker's search path?

I can reproduce it on very simple project, it's just enough to create
directory or file called "crypto":

import qbs 1.0
Application {
    name: "test"
    files: [ "*.cpp" ]
    Depends { name: "cpp" }
    cpp.staticLibraries: ["crypto"]
}

It happens beacuse gcc.js contains the following code:

for (i in staticLibraries) {
    if (File.exists(staticLibraries[i])) {
        args.push(staticLibraries[i]);
    } else {
        args.push('-l' + staticLibraries[i]);
    }
}

Another problem with this code is that it looks for file in a
directory where qbs was run. If I run qbs in some other directory
passing "-f" argument, I can build it without errors. May be qbs must
look for file relatively to project.sourceDirectory.

>
>> And another question is about linking static libraries. As far as I
>> can see in source code there is no any difference between
>> staticLibraries and dynamicLibraries properties. When I use
>> staticLibraries property, I want to be sure that it will at least
>> prefer static libraries or won't link dynamic libraries at all. But
>> "-l" option of ld by default prefer dynamic libraries to static ones.
>> May be it's better to link static libraries like this
>> ""-Wl,--push-state,-Bstatic -lcrypto -Wl,--pop-state", to be sure that
>> static version of library was linked.
>
> That looks like a good idea at the first glance. We must make sure that
> every flavor of ld supports those flags though.

It seems that ld on OSX doesn't support this. Another option is to
find libraries with platform prefix and suffix in directories
specified in libraryPaths and pass them by absolute path.

>
>
> BR,
>
> Joerg
> _______________________________________________
> QBS mailing list
> QBS at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qbs



-- 
С уважением, / Best regards
Любимов Илья / Ilya Lyubimov



More information about the Qbs mailing list