MinGW32: Linking against ImageMagick with -static flag - linker

I am currently trying to build a Windows-version of emacs that supports ImageMagick.
For that purpose I have already compiled ImageMagick with MinGW32/MSys in order to get compatible library files. Basically linking also works, though I have to add explicitly -llibMagickCore-6.Q16 and -llibMagickWand-6.Q16 to the linking command through configure.bat's --lib option.
However, the binary distribution of emacs for windows is supposed to load, even when the dependencies are absent. This behaviour I obtain when I add the linker option (configure.bat --ldflags) -static.
However, when I try to compile with ImageMagick-Support, static linking fails saying it cannot find the ImageMagick includes.
The library files are located in D:/BUILD/libraries/lib. As a minimal example:
D:\>ld -LD:/BUILD/libraries/lib -llibMagickWand-6.Q16
D:\>ld -static -LD:/BUILD/libraries/lib -llibMagickWand-6.Q16
ld: cannot find -llibMagickWand-6.Q16
The directory does however contain the static library.
D:\BUILD\libraries\lib>dir *Magick*
[...]
2013-07-02 15:16 2,585,830 libMagick++-6.Q16.a
2013-07-02 15:16 1,745,404 libMagick++-6.Q16.dll.a
2013-07-02 15:16 1,178 libMagick++-6.Q16.la
2013-07-02 15:16 5,153,712 libMagickCore-6.Q16.a
2013-07-02 15:16 977,292 libMagickCore-6.Q16.dll.a
2013-07-02 15:16 1,096 libMagickCore-6.Q16.la
2013-07-02 15:16 1,609,692 libMagickWand-6.Q16.a
2013-07-02 15:16 472,364 libMagickWand-6.Q16.dll.a
2013-07-02 15:16 1,142 libMagickWand-6.Q16.la
Any idea, what could be going wrong here? From what I understand, the .a files are the static libraries for MinGW, so the absence of .lib files (Visual Studio) shouldn't be a problem.
I have used the Unix source distribution of ImageMagick, because the Windows sources require Visual Studio for building.

I found the error looking at ld -verbose=0 ....
For some reason, when using the -static flag the lookupbehaviour changes. Without the -static flag:
...
attempt to open D:/BUILD/libraries/lib/liblibMagickWand-6.Q16.dll.a failed
attempt to open D:/BUILD/libraries/lib/libMagickWand-6.Q16.dll.a succeeded
with -static flag:
...
attempt to open D:/BUILD/libraries/lib\liblibMagickWand-6.Q16.a failed
attempt to open c:\mingw\bin\../../MinGW/usr/local/lib\liblibMagickWand-6.Q16.a failed
attempt to open c:\mingw\bin\../../MinGW/lib\liblibMagickWand-6.Q16.a failed
attempt to open c:\mingw\bin\../../MinGW/usr/lib\liblibMagickWand-6.Q16.a failed
attempt to open D:/BUILD/libraries/lib\libMagickWand-6.Q16.lib failed
attempt to open c:\mingw\bin\../../MinGW/usr/local/lib\libMagickWand-6.Q16.lib failed
attempt to open c:\mingw\bin\../../MinGW/lib\libMagickWand-6.Q16.lib failed
attempt to open c:\mingw\bin\../../MinGW/usr/lib\libMagickWand-6.Q16.lib failed
ld: cannot find -llibMagickWand-6.Q16
Writing -lMagickWand-6.Q16 instead of -llibMagickWand-6.Q16 worked.

Related

Windres not compiling .rc file no matter what I do

So I am making a desktop application using C and the Win32 API. I am also using CMake/Make in conjunction with MinGW. Everything went smoothly until I wanted to add an .rc file to the executable. From my understanding you write an .rc file which is then compiled to a .res file, then presumably you are supposed to embed it in the executable. Here's the problem however, when I attempt to compile the .rc file with the GNU utility windres it fails to compile. I always get the following error messages:
C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin\windres.exe: can't open file `page:': Invalid argument
C:\Code\C\test\resources.rc:4: fatal error: when writing output to : No such file or directory
4 | IDI_TEST_ICON ICON "test.ico"
|
compilation terminated.
C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin\windres.exe: preprocessing failed.
This occurs with every .rc file I've tried, for completeness however, here is the current test file I am trying to compile:
#include <windows.h>
#include "resource.h"
IDI_TEST_ICON ICON "test.ico"
And the resource.h file:
#define IDI_TEST_ICON 101
So the final question is the following: Why doesn't windres compile the .rc file successfully? And what can I do about in the context of using MinGW?
Edit 1:
Worth noting is that I also converted the .rc file to ANSI format since windres is notorious for yielding peculiar errors when formatted in UTF-8. Yet, the same errors occur.
windres actually generates an object file (in COFF format)
So you should run the command like this:
windres resource.rc -o resource.o
When I check the format of the generated file like this:
file resource.o
I get the following result:
resource.o: Intel amd64 COFF object file, no line number info, not stripped, 1 section, symbol offset=0x3c4c, 1 symbols
So you just need to include the generated .o file in the link step to include the resource.
For example when you run the following command you will get an .exe that won't run, but it will show the icon in Explorer:
gcc -shared -o resource.exe resource.o
After a lot of digging in old forum threads I managed to find a "solution" that works. However I still find it peculiar that this solves the problem. I followed Brecht Sanders advise and downloaded a standalone build from winlibs.com. Even this didn't solve the problem which led me to investigate possible RC_COMPILER_FLAGS which ultimately led me to the --use-temp-file flag.
This flag acts as an alternate approach to compile .rc files since it excludes the use of popen (or the equivalent of it in Windows). According to the documentation this flag should be used if the implemenation of popen is buggy on the host. What is interesting here is that the documentation states that this is known to happen on certain non-english versions of Windows. In my case I am using the Swedish language version of Windows which might explain why this is occuring.
Thus the final solution turns out to be:
windres -i resource.rc -o resource.o --use-temp-file
Which ultimately yields an object file which can then be included in the add_executable call in CMake.

How to include external library to omnetpp Makefile

I am new to omnetpp. In my source file, I include zmq.h header and I can successfully make Makefile with opp_makemake --make-so -f --deep
Next, running make does not give any errors either
Creating shared library: out/gcc-release//libtictoc_r.so
So I am expecting, that zmq library has already been linked.
However, when I run
opp_run -l tictoc_r
I get
<!> Error: Cannot load library 'libtictoc_r.so': ./libtictoc_r.so: undefined symbol: zmq_strerror
Thus I doubt if zmq library had been linked correctly.
By the way, the header files for zmq are located in the standard directory, i.e.
find /usr/include/ -name "*zmq*"
returns
/usr/include/zmq.h
/usr/include/zmq_utils.h
/usr/include/zmq_addon.hpp
/usr/include/zmq.hpp
How could I solve my problem?
Using the header files does not say anything about where the actual shared object file is present. You must add -lzmq (or whatever the library is called) to your linker flags in the project.
The easiest way is to create a makefrag file in the source folder (where the Makefile is generated) and add
LDFLAGS += -lzmq
to it. The generated Makefile will include the makefrag file and that one can add to the linker flags. (the samples/sockets example does this too)
You can also add the required extra linker flags in the IDE's project properties dialog.

Using "make all" results in Relocations in generic ELF (EM: 62)

I have a C project that I am trying to compile using a Makefile. The project has worked for me before on other machines. However, on this particular one, I keep on getting this error sequence:
Relocations in generic ELF (EM: 62)
error adding symbols: File in wrong format
I believe this may be related to the object linker that is on my machine, but I'm not sure how to go about fixing it. I tried re-installing gcc, but that had no effect either.

Unable to execute C binary on costum Buildroot

I'm unable to execute a C program on my ARM Cortex A7 running buildroot.
After executing I get this error:
./mcp23017
Could not open file (1): No such file or directory
After searching I found out that I'm missing the correct interpreter on my buildroot.
#cd /lib
ls
dhcpcd
libform.so libncurses.so.6.0
ld-uClibc-1.0.28.so libform.so.6 libpanel.so
ld-uClibc.so.0 libform.so.6.0 libpanel.so.6
ld-uClibc.so.1 libgcc_s.so libpanel.so.6.0
libatomic.so libgcc_s.so.1 libuClibc-1.0.28.so
libatomic.so.1 libmagic.so libz.so
libatomic.so.1.2.0 libmagic.so.1 libz.so.1
libc.so.0 libmagic.so.1.0.0 libz.so.1.2.11
libc.so.1 libmenu.so modules
libcurl.so libmenu.so.6 os-release
libcurl.so.4 libmenu.so.6.0 terminfo
libcurl.so.4.5.0 libncurses.so
libcurses.so libncurses.so.6
I'm really stuck, could you tell me how I can cross compile with uclibc on my i386 laptop?
Or do I have other options?
You must build your program with the cross-compiler provided by Buildroot, so that it uses the libraries matching the ones available on your ARM target. The compiler is host/bin/arm-linux-gcc.

Compiling C code with external library references

I am on RHEL 6.0 and got hold of the source code for join command(hopefully from the right source!!). I rarely work on a C code and hence finding this difficult. I am trying to compile and run the C code for join, but running into compile time errors.
g++ join.c
join.c:19:20: error: config.h: No such file or directory
join.c:25:20: error: system.h: No such file or directory
join.c:27:25: error: hard-locale.h: No such file or directory
join.c:28:24: error: linebuffer.h: No such file or directory
join.c:29:24: error: memcasecmp.h: No such file or directory
join.c:30:19: error: quote.h: No such file or directory
join.c:31:21: error: stdio--.h: No such file or directory
join.c:32:22: error: xmemcoll.h: No such file or directory
join.c:33:21: error: xstrtol.h: No such file or directory
join.c:34:22: error: argmatch.h: No such file or directory
Since I am not aware of where to find these libraries(I did google for each one and they are spread all over different websites), can anyone please guide me as to how I can link these libraries together and compile the source code of join command?
This is not a linking problem as you suggest. Instead, you get these errors because g++ can't find these files: config.h, system.h, ..., that are #included (indirectly) by join.c.
What you could do is find these files on your system, and then add as many -I<directory> options behind the g++ as there were directories you found these files in. Do man g++ for more info.
You'll also need to find the where the libraries are you need to link against. So you'll need to specify more than -I's.
On the other hand, aren't there 'configure' or other package files? Normally you don't have to specify compiler flags (like this -I) by hand. Instead, it's common that for example Makefile's are generated from such a configuration file, after which you just have to type make.
I advise you to get someone that has done this before, because you don't seem to understand the basics of C program compilation. This can cost you a lot of your precious time without results. But good luck anyway!
Perhaps you don't have everything in place to compile your code. Try installing the build-essential package.
sudo yum install build-essential
On a relevant note, I'm not aware of the script join.c but if you are looking for a way to concatenate a bunch of files together, you can do cat FILE1 FILE2 FILE3 > BIG_FILE where FILE1 FILE2 FILE3 are the files you want to join them. Under RHEL 6.0, you can use asterisks too, if there is a pattern. For example, cat FILE.00* > BIG_FILE

Resources