Nominate our 2022 Qt Champions!

[Solved] Can run project from qtcreator but not from commandline: lib not found

  • I use QtCreator to develop a project with several subdirectories that each produce a library, and some subdirectories that each produce an executable. From QtCreator I can run each of the executables fine.

    From the commandline however, I get link errors: the system cannot find my own libraries. If I run ldd I get "not found" on my own library.

    The weird thing is that everything runs from Qtcreator, so apparantly the .pro files are ok. But why can't I run the executables from the commandline?

    Can anyone point me in the right direction? Of course if you need more info (like the pro files) I would happily provide them.

    Kind regards, Guus.

  • Lifetime Qt Champion


    Qt Creator setup the environment for you so you are sure to use the correct version of Qt. Since you are running it outside you either need to take the same steps as you would for deploying your application or modify your current shell environment (don't do it system wide) in order to find the Qt libraries (LD_LIBRARY_PATH)

  • It can find the Qt libraries fine, that's not the problem. It finds all system libraries ok.

    The problem is my own libraries. The one that are part of my project. It can't find those.

  • I think I understand at least partially what is going on. My personal libraries are not in the system library path, so either I have to install them in /usr/lib64 or /usr/local/lib64 or I need to add the subdir that contains my libs to the library path.

    edit: will just have to add my subdirs to the LD_LIBRARY_PATH, even if temporarily. The way I do it now is to locally export the variable and subsequently use it. When the shell ends, the variable is unset.

    $> export LD_LIBRARY_PATH=../test:../model
    $> ./<executable-name>

    provided of course that the libraries are in ../test and ../model and the executable is in the current directory. If you use a script, you might want to use absolute paths. Alternatively do:

    $> LD_LIBRARY_PATH=../test:../model; ./<executable-name>


  • Lifetime Qt Champion

    Modify LD_LIBRARY_PATH, never pollute your system. If you want to run it from the command line you can use e.g. a bash script that setup the environment and call your application so you don't do any nasty stuff to your OS

  • SGaist: thanks for the answers. I changed the post to solved. On retrospect using LD_LIBRARY_PATH made it fairly easy to solve.

Log in to reply