How to prevent absolute paths in dynamic linker - premake

I have a solution with various projects, one of which is the main executable, and the rest are libraries the executable depends on. Each one compiles and links fine. However, trying to start the executable gives weird results. Using ldd, I see that the executable is trying to find libraries like so:
../bin/debug/libBlahBlah.so => not found
However, for each project, I'm declaring "bin/debug" (which is the output directory for these libraries) as a libdirs entry, and linking against the library by adding "BlahBlah" as a link, where "BlahBlah" is the name of the project.
I'm not even sure how to accomplish this without premake. Any help is appreciated.
The original intention was to have the library sit next to the executable then set an RPATH that searched for the library next to executable. With the way it is now, it searches for that absolute path relative to the executable... I cannot figure out how to get it off.
I'm using premake5. I've tried to use the nightly and compiling myself. Upstream is currently not compiling however.

If you are using the latest alpha or source of Premake5, you can use the "RelativeLinks" flag to use -L/-l instead of relative paths to libraries:
project "MyProject"
flags "RelativeLinks"
You will still need to set up the rpath properly though; you can do that with buildoptions() and the appropriate command line flags for your compiler. Maybe (untested):
buildoptions "-Wl,-rpath=."
That should work in Premake 4 as well.

Related

OCaml: How can I get the path to the *current module* / my project's directory?

I'm new to OCaml, but I'm trying to figure out the equivalent of __filename, __dirname from Node. That is, I need to build a path relative to the file containing the code in question.
For reference, I'm working through Ghuloum's IACC: http://ell.io/tt$ocameel
I'm building my first compiler, and I have an utterly-simplistic ‘runtime’ file (in C — temporarily) adjacent to the compiler's source-code. I need to be able to pass the path to this file, as an argument (or a pre-compiled version, I suppose) to gcc or my linker, to have it linked against my compiler's output when I invoke the linker/assembler tooling.
(This may be a stupid question — I'm at a bit of an unknown-unknown here, “how does a compiler get the runtime to the linker”, or something like that. Any commentary about idiomatic solutions to this is welcome, even if it's not a direct answer to the above question!)
If you're running the source file directly via ocaml myfile.ml, Sys.argv.(0) will give you the path to the source file and you can use Filename.dirname to get the directory from that.
If you first compile the source file into an executable and then run the executable, Sys.argv.(0) will give you the name of the executable. In that scenario it's impossible to get the location of the source code (especially if you consider that the person running the executable might not even have the source code on their system).
If you set up your project structure, so that your sources live in src/, your compiled binary in bin/ and the compiled stdlib in lib/, you could just use Filename.dirname Sys.argv.(0) ^ "../lib" as the library path for gcc. This will work whether you run ocaml src/mycompiler.ml, bin/mycompiler or just mycompiler after installing everything to /usr/ or /usr/local/.

Qt executable naming

I'm hoping this is an easy question. I have setup an Ogre3D project in QtCreator 2.6.1 using MSVC2010. I have to setup a custom build step and I noticed that the letter 'd' is appended to the name of the compiled .exe (e.g. OrgeProgramd.exe, CoolGamed.exe)
This is not critical, I was just wondering why this happens. Is it normal? The target in the .pro file is correct. I tried building with Release and I get the same thing. Any ideas?
Look through your pro/pri files and find the line, similar to this: TARGET = $$join(TARGET,,,d). If you do - that would be the reason.

Any idea about fixing this 'eclipse cdt -l error'

I am trying to link my AVR cross target application to my AVR cross target library.
The library is named Lib328P and the application is named LibTest. I have built the library and verified that the .a exists in the filesystem.
I am trying to link the library by Right clicking on the project>Clicking on C/C++ Build> Settings > AVR C++ Linker> Libraries adding Lib328P to the -l category and "${workspace_loc:/Lib328P}"
to the -L category
Here is the output to the console.
**** Build of configuration Debug for project LibTest ****
make all
Building target: LibTest.elf
Invoking: AVR C++ Linker
avr-g++ -Wl,-Map,LibTest.map,--cref -L"C:\Users\kempsa\indigo_workspace\Lib328P" -mmcu=atmega328p -o "LibTest.elf" ./something.o -lLib328P
c:/arduino-0023/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: cannot find -lLib328P
make: *** [LibTest.elf] Error 1
**** Build Finished ****
I have looked at the other posts and they suggest removing the lib and .a suffix. I am already doing that. Any help would be appreciated.
Thank you!
Sam
In your case, the linker is expecting to find the file:
C:\Users\kempsa\indigo_workspace\Lib328P\libLib328P.a
Are you sure it is present at that location? Or is it in a subfolder, possibly Release or
Debug?
This is the process that works for me:
When adding a library to be linked with your program, you make two entries. The entries are found on the project properties page by navigating to:
C/C++ Build > Settings
On the right pane, be sure to select whatever Configuration you are building at the top drop down box. (Occasionaly I make changes to the wrong configuration and wonder why those changes do not seem to occur.)
On "Tool Settings" tab is a navigation tree. On that tree, select
AVR C++ Linker > Libraries
On the right pane are two list boxes: Libraries and Libraries Path. These are where you add the two entries.
1.. In the top box, click the plus or + icon. Here you enter just the library base name. This is the library name without the "lib" and without the ".a"
For example, I have one "LibCore328v101".
That will cause the linker to look for a file "libLibCore328v101.a"
2.. In the bottom box, click the plus or + icon. Here you add the path to find that library file.
2a. You can simply type the path to the folder that contains the .a file.
2b. You can click the Workspace... button and navigate to the folder that contains your library. If you keep your libraries and programs in the same workspace this is a better method to specify a path. I use this, in in my example this text is created
"${workspace_loc:/LibCore328v101/Release}"
This is essentially a relative path to the library. This means you can create an entire duplicate of your workspace and all the library includes will still be correct.
When you see the linker output in the console window, you should see both options. In my example these are:
-lLibCore328v101 (lower case ell)
-L"F:\arduino-src\tt-wb-trunk-hg\LibCore328\Release" (upper case ell)
You can see that the Eclipse plugin has converted the relative path to the current absolute path. The linker will internally add the "lib" and ".a" to the library name.
You can repeat this process adding as many libraries and paths as needed.
For your multi-target programs, you create a different configuration for every build target. So instead of Debug and Release, you have "DebugNano" "DebugTiny", etc. For each configuration, change the path to the library.

include external libraries (from a subdirectory of the source-code-folder) in qt

I am a bit confused by the way qt handles libraries. My plan was to put the external libraries I need into the source directory, so that a do not have to install them into the system. As this doesn't seem to work (see below) I was wondering, if this is generally a bad idea or if there is some trick to it??
So I compiled the libraries and put them into /mysubdir. In the .pro-file I added
LIBS+= -L"mysubdir" -l"mylib"
I got the compiler error [projectname] Error 2 and don't know what it means.
The argument passed to -L must be an absolute path. Please give it a try with a full path, or at least -L./wcslibc. Though I'm not sure whether ./ will be recognized correctly. You can get the current path in qmake like this:
LIBS += -L$${PWD}/wcslibc -lwcs

Enabling JPEG support for QImage in py2exe-compiled Python scripts?

I'm trying to use a JPEG image in a QImage object from a Python script, with PyQt4.
The script itself works perfectly, the image loads and can be manipulated and rendered and all. However, when I try to "compile" this script with py2exe, everything works but the JPEG image. Replacing it with a PNG equivalent works, but since my program downloads images from the web, they won't always be in PNG format and I can't afford converting them all with another library.
I've discovered that JPEG image support for QImage, along with other image formats, is provided by some DLLs in the \qt\plugins\imageformats directory (they're called qjpeg4.dll and qjpeg4d.dll). I think I need to use them somehow in my executable, but I don't know how. I've tried simply copying them to my exe directory, no luck. I've tried, as indicated here, to include those files as data_files in the setup.py script, but no luck (it looks like all it does is copying these files to the exe's directory, so it changes nothing from copying them manually anyway).
I'm sure there's a handful of applications out there using PyQt with JPEG images, how do they do it? It seemed like a trivial task but I'm stuck on it now.
Also, I want my app to be cross-platform (why else would I be coding in Python?), I hope I won't run into such packaging trouble (it's not the only one) when packaging for OS X or Linux. Will I?
After hours of stumbling around with the same issue, I’d like to share the solution that worked for me on windows vista:
using python2.6
copy the following directory into your dist directory generated by py2exe:
C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats
I just dropped the imageformats directory directly into my dist directory, without any further modifications to qt.conf or anything like that. I haven’t tried it, but this may work for phonon as well.
I'll have to confess I never managed to get the py2exe + pyqt combination quite right (and, py2exe doesn't help at all with cross-platform packaging). PyInstaller seems to be much better -- the docs at http://www.pyinstaller.org/ are old, but the svn trunk is much more recent. Some docs are in slides given at the recent Pycon Italia Tre conference -- http://www.pycon.it/static/stuff/slides/distribuire-programmi-python-con-pyinstaller.pdf -- and, the slides are in English, and contain the current maintainer's email, so they should help! (And, let's all lobby the current maintainer to update the docs...!-)
Try adding a qt.conf file to your exe's directory, to tell qt where to find binaries and plugins.
Something like the following works for the simple case, where you just dump all dll's in the same dir as the exe:
[Paths]
Prefix = .
Plugins = .
Update: Then copy your plugins-contents (the imageformat/sqldriver directories etc) to the exe dir. I don't think you can load plugin dlls from the same directory as the exe. See Qt plugin doc for details on plugon subdirectories. (Or, leave out the 'plugins = .' and copy the plugins dir to the exe dir, so you have /plugins/imageloaders/qjpeg4.dll).
Etienne -- Thank you for the tip. After much reading and trial-and-error, I arrived at the same conclusion: use PIL to show jpegs in a py2app-generated app.
http://www.thetoryparty.com/wp/2009/08/27/pyqt-and-py2app-seriously-i-dont-know-what-to-do-with-you-when-youre-like-this/
What I guess is that the proposed solutions for py2exe/Windows don't necessarily apply to py2app/OSX.
I'm on OSX Leopard.
Let's suppose you have an application MyApp.app.
Put the libraries libqjpeg.dylib and libqgif.dylib in
MyApp.app/Contents/plugins/imageformats/
Put this in qt.conf in MyApp.app/Contents/resources/:
[Paths]
Prefix = .
Binaries = .
On my machine (Leopard) this works.
After trying all the above solutions in vain, I just ended up using PIL to load my images. Since I wanted to convert these images to a texture in an OpenGL Qt widget, the result was the same whether I load the image using Qt or PIL. Still, I'm baffled that such a basic thing as loading JPEGs is so complicated in a GUI library as well-known and widely used as Qt.
I had the exact same problem. Fixed it using this : http://mail.python.org/pipermail/python-list/2008-June/669374.html
Copy Qt plugins to the directory: $YOUR_DIST_PATH/PyQt4/plugins;
Copy qt.conf to your dist directory;
Edit qt.conf, change Prefix to ./PyQt4
For me, the problem was solved just copying the "qt.conf" for the directory of the executable.
You can find the "qt.conf" in ...\PythonXX\Lib\site-packages\PyQt4\qt.conf.
Thanks for help.
Everything above failed for me until I realized that I was bundling the .exe (that is, I had the option "bundle_files" : 2 in my setup.py. I changed it to bundle_files = 2, and now it works great.
The above solutions are fine. Specifically, I just added the following line in my setup.py:
data = [ ("imageformats", glob.glob("C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats*.dll")) ]
(in addition to other files, of course).
Then, the image loading dlls are in MY_EXE_DIR/imageformats
I didn't need a qt.conf to make this work, though I'm sure you could use it if you want to keep your directory tree less cluttered.
It is possible to use the JPEG plugin with a py2exe'd script, even using bundle_files. You need to arrange two things to get this to work properly:
Copy PyQt4/plugins/imageformats to the output directory of py2exe (default: dist)
You only have to copy the formats you actually need.
When use the bundle_files option you need to execlude the Qt dll files from the
zipfile using the --dll-excludes option for pyexe.
You still have to copy the Qt DLLs to the output directory some other way (such as
by using the data_files option).
on windows, suggested solutions work perfectly.
however, on osx can't make it work even with instructions here above.
question is: the libqjpeg.dylib and libqgif.dylib files are located in the /Developer/Applications/Qt/plugins/imageformats/ directory, and that if you have installed Qt itself, not just PyQt. these files do not work for me.
in PyQt distribution, i see the files libqjpeg.bundle and libqgif.bundle in /opt/local/libexec/qt4-mac/plugins/imageformats/, however these are not libraries, and btw i cannot open their contents either, even if they have the .bundle extension. using these files instead does not work either.
i am curious to know what have you done to make it work on osx. i have installed PyQt following this guide.
Thanks for your helpful answers for the question! I have encountered same problem as you did and no solutions could help. Hopefully, I was using VCS and found that old version of my app loaded JPEG images correctly and new versions stopped doing it. I caught this bug using PySide v1.2.2.
To enable libraries loading, I used the same solution as #Macke did (i.e. added and edited qt.conf).
My qt.conf was next:
[Paths]
Binaries = .
Plugins = qtplugins
C:\Python27\Lib\site-packages\PySide\plugins directory was copied to qtplugins directory, so I had next directories:
qtplugins\accessible
qtplugins\codecs
qtplugins\graphicssystems
qtplugins\iconengines
qtplugins\imageformats
I had next code:
class NotesCalendar(QtGui.QCalendarWidget):
note_icon = QtGui.QImage("res/16note.png")
Moving class variable NotesCalendar.note_icon to constructor solved the problem and Qt started loading its libraries correctly. Seems that class variable constructor interrupted some internal PySide stuff.
It works with no problems on Windows. Specifying correct qt.conf and copying plugins directory is enough to enable JPEG support in py2exe + PySide build. Of course, you must have no problems in your own code.
I hope this will save someone a day! ;)

Resources