How does `ld` find secondary dependencies for shared objects? - ld

I have a situation where we link to some shared library libfoo.so, that in turn depends on libbar.so. In case we link an executable that depends on libfoo.so directly we compile it by giving the flags:
-L<location of libbar.so> -lfoo
This however picks up a libbar.so in the system path instead of the location specified on the command line with the incorrect set of symbols resulting in undefined references. If we change the command to:
-L<location of libbar.so> -lfoo -lbar
The right libbar.so is found by ld. Is this to be expected? How can we tell ld to find a secondary dependency in some location without explicitly linking to it?

If you do not specify -lbar, the indirect dependent libbar is added implicitly. In this case the compile time linking search mechanism for this library is different (it is then similar how the runtime linker ld.so would search the library at runtime). Have a look at the -rpath-link option in the ld manual. There you can see that searching in -L directorys for this case is only done on SunOs systems. The best way to specify a compile time linking search path for indirect dependencies ist to use the -rpath-link option, because this has the highest search priority.

Related

VScode Haskell Go To Definition doesn't work for some symbols

I'm getting started with Haskell and VSCode. I've forked and downloaded a repo with Haskell code. I've followed instructions for setting up a nix-shell correctly for this repo. I can successfully invoke cabal build and haskell-language-server for week 1 examples.
I've started up VSCode from within nix-shell and I can see that the language server is reporting symbol information to VSCode. For example:
However, I often find that if I try to Go To Definition VSCode reports that no definition is found:
For many of these symbols I find that if I hover my cursor over the symbol I'm shown where the symbol is defined:
Othertimes, I find that Go To Definition correctly resolves. For example, AuctionSchema on this line resolves correctly, while AuctionSchema on this line does not.
Why does Go To Definition only sometimes work? Is there a way to fix this?
I use emacs within NixOS, and I find that definitions are only found when they’re within the project I’m working on. Sometimes if I’m in src and the definition is in lib it won’t find it either. I just assumed that Haskell Language Server cannot use Cabal or Hpack to find definitions, but only follows types within the directory branch the current source resides. Yep, that’s annoying, but it seems to be what’s currently on offer.

determining the properties used by a previous build

After some time, I went to a project to redo a build and the command I give results in:
qbs build -p archive config:release modules.cpp.useRPaths:false
Restoring build graph from disk
ERROR: Property values set on the command line differ from the ones used for the previous build. Use the 'resolve' command if you really want to rebuild with the new properties.
Is there any way to determine which properties were set in the previous build?
No, the command-line frontend does not expose this functionality. But independent of that, it would be helpful if the error message listed the differing properties. You might want to create a task for that at bugreports.qt.io.

Why do I get error messages like "Unable to activate XX analyzer" in vscode?

I have added some extensions in vscode and after that, every time I open/switch to a tab with a C file, I am getting a dropdown with three error messages about not being able to activate analyzers. Why?
Here are the extensions:
and here are the error messages:
That should be caused by c/c++ Advanced lint module, well the same error can be caused by others modules, those errors occur, when you don't have those modules that you are getting warning about installed, in this case Clang, CppCheck, and flexeLint. Well for the two first you can download and install them from here:
clang: http://clang.llvm.org/ (go to download section)
cppCheck: http://cppcheck.sourceforge.net/
flexlint: here the bad news, that's not a free product, and some kind of expensive. http://www.gimpel.com/html/flex.htm
for those programs, once installed, by default should be added to the system path environment variable (if not you can do it yourself, cppcheck don't add automatically to path in windows), the thing if they are added to the path, vscode or the calling plugin here "c/c++ Advanced lint", will recognize them, because will test if the command is recognized at the console level. If you don't want to add those tools to path, you can still specify in parameters the path to those tools executables, for that you can follow the instruction for every module here they are :
cppCheck : https://marketplace.visualstudio.com/items?itemName=matthewferreira.cppcheck (using this setting cppcheck.cppcheckPath:)
clang: (clang.executable) see here: https://marketplace.visualstudio.com/items?itemName=mitaki28.vscode-clang
flexlint: (c-cpp-flylint.flexelint.executable)
and of course setting the path to executable in each one of those settings.
well you can also check that : https://marketplace.visualstudio.com/items?itemName=jbenden.c-cpp-flylint
it's so often that plugins depends on others programs, on which you need to install manually, and every time, you need to read the documentation for the module to be installed, to see what configuration you need to do.
for the warning about flexlint you can disable it by adding this to the user settings :
"c-cpp-flylint.flexelint.enable": false
that disable completely the use of flexlint, and so the plugin will not search for it. I'm not sure, may be setting cppcheck is sufficient, otherwise you have that to set. I personally have that set. Of course unless you count to buy the product and then just set the path.
hope you all, all the best!

Installing haxe

I have a problem with programming in Haxe. Whenever I try to run a code, I get an error:
Please don't add haxe/std to your classpath, instead set HAXE_STD_PATH env var.
I tried to find a solution - according to multiple sites, I'm supposed to change the environment variable HAXE_LIBRARY_PATH to HAXE_STD_PATH and set the value to actual path to the std file in my haxe folder. In my case, there was no such variable among my env vars, so I made HAXE_STD_PATH as a new one - and I still get the same error.
I'm using FlashDevelop and when I try to search for any class that would reference std, I can see in Type Explorer that there is a classpath that leads straight to haxe/std, which should not happen IMO. I looked at classpaths in Properties and the path to std was not listed, so I could not change it.
So problem could be in the classpath or in FlashDevelop settings.
Did anyone have the same problem?
Oh, and BTW I'm using Windows - and yes, restarting did not help.
I removed all: FD including program settings and HaxeToolkit (the whole map).
Then I reinstalled FD, Haxe (using the apps window from FD), Lime and openFL (from command window).
Now I don't get this error anymore.

xcode project-/target-settings-syntax for linker flag force_load on iPhone

I am confronted with the double bind. On the one hand, for one of the 3rd party static libraries my iPhone application uses, the linker flag -all_load has to be set in the application project or target settings. Otherwise, the app crashes at run-time not finding some symbols called internally from the lib. On the other hand, for another 3rd party static lib, -all_load must not be set on application level, or the app won't build thanks to a "duplicate symbols" linker error.
To solve this issue, I now want to use force_load instead of load_all, as it due to documentation it does the same like all_load, but only for the passed path or lib-file, instead of all libs.
The problem with force_load is, I do not have a clue how to pass a path or file as parameter with it, when passing it via XCode project- or target-settings. All syntax-possibilities I tried either lead xcode to thinking it's another linker flag instead of a parameter to the previous one, or the linker throwing syntax related errors, or the flag simply does nothing at all.
I also opened the .pbxproj-file in a text-editor to edit it to the correct command line syntax manually. But when reloading the project with XCode, it auto-changes the syntax into interpreting the parameter to force_load as a separate flag.
Anyone have an idea on this issue?
I just tried this. I've compiled a static armv6, armv7, and i386 fat binary of PCRE for use in my iPhone project. My project normally just has my library added to the project and that links fine. So I unchecked the target membership box for libpcre.a and rebuilt. As expected, I get a bunch of missing symbol linker errors for the pcre symbols. Then I opened the target settings window and edited the "Other Linker Flags" section. I added:
-force_load lib/pcre/libpcre.a
The lib directory is in the same directory as my project.xcodeproj file.
It linked fine so I know the force_load command worked (and I can see it added to the build flags when xcode builds the file).
Hope that helps.
Update:
I also tried adding a system library to the "Other Linker Flags" line like so:
-force_load src/pcre/libpcre.a -force_load ${SDKROOT}/usr/lib/libz.dylib
That worked too.
I just added force_load to our project and all is fine using the simplest syntax possible. The library is a dependency built in the same project. The library is therefore included on the link command-line twice: once as a normal input file and once as an argument to -force_load. You might want to put quote characters around the argument.
In fact, I've even got this working using configuration-dependent settings (because the path is obviously different for debug vs. release and device vs. simulator).
Good luck.