Getting exe when building dll using libtool - c++

I'm trying to compile .dll of this project on windows using MinGW. Everything goes ok except one point: output is the .exe file - not .dll.
Here is the notification, that libtool gave me:
*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.
Well, I've not found anywhere in project option -no-undefined and that's why I wonder what symbols(and how??) should be fixed to get needed .dll?
Maybe there are some issues with linker? I dont know where to change($LIBRARY_PATH = /c/mingw already) it and that's why during make this warning pops up:
*** Warning: linker path does not have real file for library -lz.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libz and none of the candidates passed a file format test
*** using a file magic. Last file checked: c:/Strawberry/c/bin/../lib/gcc/x86_64
-w64-mingw32/4.8.3/../../..//libz.a
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

Looks like your program need zlib, but c:/Strawberry/c/bin/../lib/gcc/x86_64
-w64-mingw32/4.8.3/../../..//libz.a is not valid (different target architecture - x86 vs x86_64?). You need to get a real zlib, compile for the same architecture and point your program to it.

you can use a .cmd file with following content
::source code file path
set src_path=source.cpp
::output file path
set bin_path=yourlib.dll
::library you need
set libs=-lmingw32 -lkernel32 -lshell32 -luser32 -lwsock32 -lws2_32 -lole32 -loleaut32
::windows subsystem
set sub_sys=-mwindows
::cpp version used by g++
set cpp_ver=-std=c++1y
::jump to g++ path
cd "%your_mingw32_folder_path%\bin\"
::run g++ with args
g++.exe "%src_path%" -o "%bin_path%" -Wall -W -w -static %sub_sys% %libs% %cpp_ver%
pause

Related

SDL2_Gfx - Linker issue with cygwin

I'm struggling to compile SDL_Gfx with cygwin.
The configure script worked without issues.
Here's the last makefile command:
/bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -I/usr/local/include/SDL2 -Dmain=SDL_main -no-undefined -release 1.0 -version-info 0:1:0 -o libSDL2_gfx.la -rpath /usr/local/lib SDL2_framerate.lo SDL2_gfxPrimitives.lo SDL2_imageFilter.lo SDL2_rotozoom.lo -L/usr/lib -lcygwin -lSDL2main -lSDL2
libtool: link: warning: library `/usr/lib/libSDL2.la' was moved.
And here's the linker "warning" message.
*** Warning: linker path does not have real file for library -lSDL2main.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libSDL2main and none of the candidates passed a file format test
*** using a file magic. Last file checked: /lib/libSDL2main.a
If i try to ignore this, I'm getting this error when I try to use the library inside my application:
In function `pixel':
/usr/local/lib/SDL2_gfx-1.0.1/SDL2_gfxPrimitives.c:75: undefined reference to `SDL_RenderDrawPoint'
/usr/local/lib/SDL2_gfx-1.0.1/SDL2_gfxPrimitives.c:75:(.text+0x11): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SDL_RenderDrawPoint'
UPDATE: I tried to switch compiler to use mingw64 instead of cywin. I'm having a similar issue, I think this is related to libtool since I can compile an external programs with similar c/l flags without issues.
I don't know what I can try I ran out of ideas, please help.
Thank you

Add C++ Library to eclipse C++ Project

I am attempting to add an existing library to Eclipse. I use a cross compiler for C++ with the Eclipse IDE, installed on a virtual linux debian machine.
The mmapGpio lib is found here.
/mmapGpioBasicRev1.tar.gz has a cpp and an h file with a small demo program.
I have compiled this code without a problem. A .o file is generated. I've archived the file successfully with ar -q libmmapGpio.a mmapgpio.o
I've placed my libmmapGpio.a in ~/.../UserLib directory
I've placed my mmapGpio.h in ~/.../UserInclude
At this point all is OK.
I open a new project that uses the mmapGpio library:
#include "mmapGpio.h"
#include "stdio.h"
int main(void){
mmapGpio rpiGpio; // instantiate an instance of the mmapGpio class
rpiGpio.setPinDir(17,mmapGpio::OUTPUT); // set GPIO17 to output
while(1) {// toggle pin as fast as possible
rpiGpio.writePinHigh(17);
rpiGpio.writePinLow(17);
}
return 0;
}
So cross-compilation is done, but linker say cannot find -llibmapGpio!
I have made declaration in the properties project; C/C++ General
includes path : /home/octopuss/rpi/UserInclude (the mmapGpio.h file)
Library path : /home/octopuss/rpi/UserLib (the libmmapGpio.a file)
Libraries : libmmapGpio
Why do I receive this message?
for detail -> console view
03:16:30 **** Build of configuration Debug for project Gpio1 ****
make all
Building file: ../Gpio1.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/home/octopuss/rpi/UserInclude -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Gpio1.d" -MT"Gpio1.d" -o "Gpio1.o" "../Gpio1.cpp"
Finished building: ../Gpio1.cpp
Building target: Gpio1
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L/home/octopuss/rpi/UserLib -o "Gpio1" ./Gpio1.o -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /home/octopuss/rpi/UserLib/libmmapGpio.so when searching for -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lmmapGpio
collect2: error: ld returned 1 exit status
make: *** [Gpio1] Erreur 1
error :
skipping incompatible /home/.../UserLib/libmmapGpio.so when searching for -lmmapGpio
ld: cannot find -lmmapGpio
"why this message ?"
It's because with your settings, the linker actually looks up for a library file named liblibmmapGpio.a.
"... so crosscompilation is done but linker say "cannot find -llibmapGpio" !
...
- Libraries : libmmapGpio"
You just need to specify the library without the lib prefix in the linker library settings:
mmapGpio
The Eclipse CDT Builder passes this as a -l option to the linker, which automatically extends to search for libmmapGpio.a at the specified additional pathes.
See also this Q&A for more illustrated samples and links:
Problems importing libraries to my c++ project, how to fix this?
I found the problem ... my .so lib wasn't ARM cross compiled so there is a X86 library not compatible whith my ARM Programm.
I solve this to set erm-linuxgnuabihf- prefix and his path to cross setting parameter.
Thanks to TTAVAR PEI and Scott Stensland
enjoy

gcc compiler cant find external library

I'm having a question about the Boost library. I compiled it and i can use the library in a project. Now i made a new project and wanted to include . I added the library in the linker and in the C++ compiler. I'm using Eclipse
This is my compiler output:
18:45:16 **** Incremental Build of configuration Debug for project Asterretje ****
Info: Internal Builder is used for build
g++ -o Asterretje.exe main.o Vertex.o RouteCalculator.o Reader.o Graph.o Edge.o -llibboost_regex-mgw48-mt-1_55
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -llibboost_regex-mgw48-mt-1_55
collect2.exe: error: ld returned 1 exit status
18:45:17 Build Finished (took 915ms)
Does anyone know how to solve this?
Add switch -L<dir>, where <dir> is directory of boost libraries. And you should cut first 'lib' part from library file name, for example for libmylib.so you should pass -lmylib
Thanks for all the help
I've found the problem. I forgot to insert the searchpath.

How to use external .h and .o files in current project with Eclipse CDT

I was given three files to test my project: Test1.cpp SignalMasker.h and SignalMasker.o when Test1.cpp includes the SignalMasker.h file and files from my project. Putting both in the source folder returns undefined references such as:
error: undefined reference to 'SignalMasker::~SignalMasker()'
I tried to use the project preferences and add the .o file to it. Under GCC C++ Linker-> Miscellaneous -> other objects. When selecting a file it inserted a new record as:
"${workspace_loc:/${ProjName}/source/SignalMasker.o}"
Building it didn't seem to resolve the issue so I added to the Linker flags the -l flag and got:
Invoking: GCC C++ Linker
g++ -l -o "uthreads" ./source/Scheduler.o ./source/SchedulerStarter.o ./source/Test1.o ./source/Thread.o ./source/main.o ./source/uthreads.o /home/tom/workspace/uthreads/source/SignalMasker.o
g++: error: uthreads: No such file or directory
make: *** [uthreads] Error 1
So I went back to other objects and replaced the automatic generated variable to:
./source/SignalMasker.o
And building gave me:
make: *** No rule to make target `source/SignalMasker.o', needed by `uthreads'. Stop.
These are all solutions I've found in SO and none seem to work including making a library and trying to include it. Please help.
EDIT: uthreads is also the name of the project.

Qt/mingw32 undefined reference errors... unable to link a .lib

I am new to Qt and have one error I am unable to fix.
I have a bunch of windows (VS2005) static library file (.lib). And I am testing if they work well with Qt. So I took the most simple library that I have. (Called MessageBuffer).
So I added MessageBuffer.h to the main.cpp, and added the location of those file in the INCLUDEPATH of the .pro.
Until then everything seem fine, I can use the class and Qt IDE show all method and everything. So to me it look like it found the .h file.
Now I added the MessageBuffer.lib (VS2005/Debug build) in the .pro like this:
LIBS += E:/SharedLibrary/lib/MessageBufferd.lib
I have also tried the following:
win32:LIBS += E:/SharedLibrary/lib/MessageBufferd.lib
LIBS += -LE:/SharedLibrary/lib -lMessageBufferd
win32:LIBS += -LE:/SharedLibrary/lib -lMessageBufferd
Here is the content of my .pro file:
QT += opengl
TARGET = SilverEye
TEMPLATE = app
INCLUDEPATH += E:/SharedLibrary/MessageBuffer
SOURCES += main.cpp \
silvereye.cpp
HEADERS += silvereye.h
FORMS += silvereye.ui
OTHER_FILES +=
win32:LIBS += E:/SharedLibrary/lib/MessageBufferd.lib
They all give me the same errors: (and I get the same even if I don't include the .lib)
Running build steps for project SilverEye...
Configuration unchanged, skipping QMake step.
Starting: C:/Qt/2009.03/mingw/bin/mingw32-make.exe -w
mingw32-make: Entering directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
C:/Qt/2009.03/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\SilverEye.exe debug/main.o debug/silvereye.o debug/moc_silvereye.o -L"c:\Qt\2009.03\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind E:/SharedLibrary/lib/MessageBufferd.lib -lQtOpenGLd4 -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
mingw32-make: Leaving directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
debug/main.o: In function `Z5qMainiPPc':
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:12: undefined reference to `MessageBuffer::MessageBuffer()'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:13: undefined reference to `MessageBuffer::Append(char*, int)'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:17: undefined reference to `MessageBuffer::~MessageBuffer()'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:17: undefined reference to `MessageBuffer::~MessageBuffer()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\SilverEye.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project SilverEye
When executing build step 'Make'
Can anyone help please?
Based on the question Use libraries compiled with visual studio in an application compiled by g++ (mingw) and the MSDN forum post I can't mix VC & GCC it does not appear you can link a gcc application with visual c++ compiled libraries.
The solution would be to recompile everything with the same compiler.
The MinGW FAQ discusses this problem and offers a solution:
Create a definition file using reimp (for lib files) or pexports (for dll files).
Remove the underscore prefixes from the stdcall functions.
Use dlltool to convert the MSVC library into a MinGW library with the new definition.
That didn’t work. We finally removed the ordinals from the function names, which caused it to compile. But the program wouldn’t run because it couldn’t find the linked functions in the DLL. Finally, after consulting the MSDN documentation for definition files, we changed the build instructions:
Create a definition file using reimp.
For each stdcall function (formatted as _name#ordinal) add a line name = _name#ordinal, allowing MinGW to map its stdcall naming convention to that of MSVC.
Use dlltool to convert the MSVC library into a MinGW library with the new definition.
It worked! To compile the project you must simply:
Download and install the Qt/Windows package, which includes MinGW.
Download reimp and drop it into the MinGW/bin folder.
Download the development packages for the third-party libraries and point an environment variable to that location.
Build the project with the usual qmake/make commands.
Taken from:
http://blog.outofhanwell.com/2006/05/01/linking-msvc-libraries-with-mingw-projects/
I assume that you have used the MessageBuffer library in another application with problems. The error looks like it either cannot find the library or the MessageBuffer class is not being exported.
Have you tried putting -l on front of the library in the pro file?
win32:LIBS += -lE:/SharedLibrary/lib/MessageBufferd.lib
See my other answer. I added the other answer because I didn't want to make this answer any more messy than it already was.
Tried so far:
Not a typo, d is appended to the library
Using the lib extension is correct as seen in the output