undefined reference to _imp__GetDIBits#28 with GetDIBits function - c++

I'm trying to use the GetDIBits function with C++ (with QtCreator) on Windows. The code compiles but can not link with the error
undefined reference to _imp__GetDIBits#28
I tried to link add
LIBS = C:/MinGW/lib/libws2_32.a
to my .pro file but nothing changed.
is it the correct library or another one ? Thank you

Link with Gdi32.lib.
In general, to figure out which library to link with, look up the API on msdn.microsoft.com and then scroll to the bottom of the page for the headers and lib requirements.
Example here

Related

C++ linking with another libc with g++ - Specifying the right crt file

I'm trying to compile my c++ code with another libc with g++.
To do that, I used the rpath option to provide the path to the new libc.
I have also provided the dynamic-linker option to provide the corresponding linker.
The problem is that I'm getting this error:
path_to_old_libc/crt1.o: In function `_start': undefined reference to `__libc_csu_fini'
Thus, I also have to give the path to the new crt file located at path_to_new_libc
The problem is that I don't see any option in the manual that would allow to do that. I though about the nostartupfile or nostdlib options, but that would just ignore the crt file which is not what I want.
So far, the compilation looks like that:
g++ -Wl,--dynamic-linker=/.../.../.../glibc-2.22/build/elf/ld-linux-x86-64.so.2 -Wl,-rpath,/buildroot/output/build/glibc-2.22/build ...
Therefore, I'm looking for a way to add the right crt file.
Thank you in advance for your help

[c++][cygwin][gcc] Boost Filesystem linking from DLL via BOOST_FILESYSTEM_DYN_LINK

I've very simple piece of code witch utilize Libboost filesystem to check if file exist or not. Additionally I want to use libboost as dll library, not static one. Here you have what I written few minutes ago:
void Hex2bin::convert(string filename, vector<uint8_t>* decodedBytes) {
const path fname(filename); // from boost::filesystem
if (exists(fname)) {
;
}
else {
throw new EFileDoesntExist;
}
}
Unfortunately when I remove -lboost_filesystem from linker settings and add macro BOOST_FILESYSTEM_DYN_LINK globally in Eclipse configuration I get only such linker error as below:
/usr/include/boost/filesystem/operations.hpp:446: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
Source file compiles without any warning. When I revert back to -lboost_filesystem everything works OK, but I assume that then library is statically linked to EXE file. Have anybody any idea what is going wrong? Or maybe I have wrong understanding how libboost can be linked?
No. You still need to specify-lboost_filesystem even if the library is a shared object rather than a static library. In fact, most linkers will prefer to link against a shared object rather than a .a if both are present (there are ways to change this if necessary).
Use ldd to see the shared libraries an executable is linked against.
Only Windows (specifically MSVC++) supports "auto-linking" with Boost. On Linux, you'd either link against libboost_filesystem.so or libboost_filesystem.a, but in either case you need to link explicitly.

link failure - undefined references to graphical functions

I have working C++/Windows program compiled with Visual Studio 2008. The program consists of just two .cpp files. I am now attempting to compile and link it using MinGW. So far I have successfully compiled both source files without error, but now when I link them with the command...
g++ -o program.exe file1.o file2.o
... I get many instances of "undefined reference to.." assorted graphics related functions like:
GetStockObject, SelectObject, MoveTo, LineTo, SetPixel, TextOut, BitBlt, CreatePen etc.
I am not getting undefined references for any other types of windows call. Clearly I have missed something in my linker command line, but cant work out what.
Since this spans two (similar) prior answers, I'll add it as a separate answer, rather than as duplicate comments on those preceding answers.
Better, rather than jumping in and adding "-lgdi32", you should first add the "-mwindows" option; this tells GCC that you are building a Windows application, (its default is a "console" application type), and so causes it to automatically bind a number of additional graphics device interface specific libraries, (one of which is gdi32.dll). Only if adding this option still fails to resolve all symbols need you worry about what other non-default libraries may be needed.
All these functions are located in Gdi32.dll. You need to link Gdi32.lib to make them work. You can try:
g++ -o program.exe file1.o file2.o -L MinGW\lib -lgdi32
By the way, Microsoft documents each function extensively and names the appropriate library. For example: GetStockObject.
You can solve it like this:
For each undefined reference, look up that function at Microsoft Developer Network documentation. In your case, google for
GetStockObject msdn
The MSDN page describing the function contains at the bottom a section "Requirements". Here it lists required DLLs that you need to link to.
In case of GetStockObject, that's Gdi32.dll
Extend your command line to include -lGdi32
Retry the linking and repeat for any remaining undefined references.

Android NDK:undefined reference to ' '

I am trying to build a library file of g729 codec.i have source of this codec and trying to build using Android NDK.Almost all object files are built but at last i am getting this error.
But i am stuck with this error. can anyone explain the meaning of this error and what should i do to solve this?
./obj/local/armeabi-v7a/objs/g729_jni/g729/cod_ld8a.o: In function `Coder_ld8a':
/root/g729/jni/g729/cod_ld8a.c:267: undefined reference to `Pitch_ol_fast'
/root/g729/jni/g729/cod_ld8a.c:325: undefined reference to `Pitch_fr3_fast'
/root/g729/jni/g729/cod_ld8a.c:328: undefined reference to `Enc_lag3'
/root/g729/jni/g729/cod_ld8a.c:344: undefined reference to `G_pitch'
collect2: ld returned 1 exit status
Thanks
Edit
I have solved this error but is it feasible?
I have added this line in Android.mk
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
If you are compiling the sources and you want to link the resulting library you can use one of the following variables in your Android.mk file
LOCAL_STATIC_LIBRARIES:
The list of static libraries modules (built with BUILD_STATIC_LIBRARY)
that should be linked to this module. This only makes sense in
shared library modules.
LOCAL_SHARED_LIBRARIES:
The list of shared libraries modules this module depends on at runtime.
This is necessary at link time and to embed the corresponding information
in the generated file.
For more details have a look at the android NDK documentation that you can find in the ndk folder.
Otherwise if you have to link a prebuilt library there is a section in the Android NDK documentation that tells you how to achieve the result. An on-line version of these documents is also here(PREBUILTS).
UPDATE 09/01/2017
Documentation about Prebuilt libraries can be found here

Compiling TagLib into Qt C++ Project on Windows

I am currently trying to make the move from C# and break free from my platform boundaries by using Qt / C++.
I was using TagLibSharp in my old project, but I'm now trying to use the original C++ source found here:
http://developer.kde.org/~wheeler/taglib.html
I am in a world of hurt trying to compile this into my application. Most of this Linux based C++ is gibberish to me and I don't know how to properly include this library into my project with Qt. I'm using Qt Creator for the bulk of my work (everything I possibly can).
Can anyone please point me to some helpful tutorial or guides? Anything to help me understand what I am even doing with this source would be greatly appreciated. I have a very thorough understanding of C# and Windows programming, but I don't exactly have a good handle on what I'm doing with these types of open source projects.
Thanks!
EDIT - THE ANSWER IS HERE
I decided to post another question that was a bit more refined for it.
Compiling static TagLib 1.6.3 libraries for Windows
Some older edits...
I now have TagLib compiled with Qt, but am running into "Undefined reference" errors.
*.pro
INCLUDEPATH += ../$${TARGET}/taglib-win32
LIBS += -L"..\\$${TARGET}\\taglib-win32"
LIBS += -llibtag #It seems to want this to be a *.dll, not a *.a?
DEFINES += TAGLIB_NO_CONFIG
*.cpp
#include <tag.h>
#include <fileref.h>
...
//None of these work, even though they are similar to examples given in TagLib source.
TagLib::FileRef f("03.flac");
TagLib::String test = f.tag()->album();
TagLib::FileName *n = new TagLib::FileName("test");
TagLib::FileRef *f = new TagLib::FileRef();
Here are some examples of the exact errors:
./debug\mythread.o:C:\Users\jocull\Documents\My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:20: undefined reference to `_imp___ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE'
./debug\mythread.o:C:\Users\jocull\Documents\My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:21: undefined reference to `_imp___ZNK6TagLib7FileRef3tagEv'
./debug\mythread.o:C:\Users\jocull\Documents\My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:42: undefined reference to `_imp___ZN6TagLib6StringD1Ev'
./debug\mythread.o:C:\Users\jocull\Documents\My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:42: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
collect2: ld returned 1 exit status
Command line steps using g++ (Mac/Linux)
./configure --enable-shared=false --enable-static=true
make
??? No *.a or *.lib files created
If you're new to C++ programming there are several issues you have to grasp to accomplish your task:
Source files (*.cpp) contain the actual source code, while header files (*.h) just declare what's inside a source file. You have to include all headers in your source files that use classes/functions/variables from other source files.
You need to understand how the preprocessor works. AFAIK C# does not have one. The wikipedia article should give you a good overview: http://en.wikipedia.org/wiki/C_preprocessor
Assuming you want to use TagLib as a dynamic library you have to create a Qt project for just building TagLib as a .dll (.pro file directives TEMPLATE=lib, CONFIG+=dll)
If you want to create a dynamic library out of a source files you have to mark the functions you want to use later as exportable. In TagLib this is done by defining the preprocessor macro MAKE_TAGLIB_LIB (in your taglib .pro file: DEFINES+=MAKE_TAGLIB_LIB)
Then you have to build the dynamic library (in your pro file: TEMPLATE=lib, then adding all sources and headers of taglib). When you use gcc this will result in two files TagLib.dll and libTagLib.a.
When building your application you have to include the header files of TagLib in your source and tell the compiler about the library (in your .pro file: LIBS+=libTagLib.a)
In your code you simply include the header file from your library. Let's say you want to use TagLib::Tag in your source file, then you must #include <taglib/tag.h>; You also have to tell the compiler (to be precise: the preprocessor) where it can find the taglib directory. In your .pro file you do this by adding INCLUDEPATH+=/path/to/taglib.
These are the big points and are not an in-depth explanation of what you have to do. Please ask more detailed questions if you have a problem when realizing this points.
For more information look at the qmake manual: http://doc.trolltech.com/4.6/qmake-variable-reference.html#libs