Using Qt Creator with Allegro - c++

I want to get Allegro 4 (MSCV 9) to work with Qt Creator. I am using Windows XP.
I have added these lines to my .pro:
INCLUDEPATH += C:/Allegro/include \
LIBS += C:/Allegro/lib/allegro-4.4.2-md.lib \
C:/Allegro/lib/allegro-4.4.2-monolith-md.lib \
C:/Allegro/lib/allegrogl-0.4.4-md.lib \
C:/Allegro/lib/loadpng-1.5-md.lib \
My code looks like this:
#include <iostream>
#include <allegro.h>
volatile int closedWindow = false;
void CloseButtonCallback() {closedWindow = true;}
END_OF_FUNCTION(CloseButtonCallback())
int main()
{
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 400, 300, 0, 0);
set_window_title("Testing");
LOCK_FUNCTION(closeButtonCallback)
set_close_button_callback(CloseButtonCallback);
while(!closedWindow){}
allegro_exit();
return 0;
}
END_OF_MAIN()
And I keep getting errors like these, when I try to compile:
main.obj:-1: error: LNK2019: unresolved external symbol imp__allegro_exit referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_close_button_callback referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_window_title referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_gfx_mode referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol _imp_set_color_depth referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)
main.obj:-1: error: LNK2019: unresolved external symbol __imp_install_allegro_version_check referenced in function "int __cdecl _mangled_main(void)" (?_mangled_main##YAHXZ)

I'm using precompiled Allegro 4.4 for MinGW from http://www.allegro.cc/files/. I merged those three folders (bin, include, lib) inside the archive to MinGW folder which has same folders as well. Then added LIBS += liballegro-4.4.2-mt to .pro file and everything works fine.

Looks like you have to use the GCC-compiled version of Allegro for Qt.
Something like
LIBS +="path_to_allegro_for_mingw/lib/liballegro-4.4.2-md.a"
GCC uses different name mangling and different export libraries, so even while you're using the Allegro dlls, MSVC-compiled .lib wouldn't work.

Related

__declspec(dllimport) in release mode and debug mode in QT

i want to use taglib in my QT project on windows, so i build taglib and zlib from source like below:
cmake CMakeLists.txt
cmake --build --config release
cmake command uses visual studio compiler, i build zlib and taglib from source with above command with no error, i added their include and lib path to QT project .pro file like below:
INCLUDEPATH+=F:\project\TAGLIB\taglib\taglib F:\project\TAGLIB\taglib\taglib\toolkit F:\project\TAGLIB\taglib F:\project\zlib-1.2.11\Release F:\project\zlib-1.2.11
LIBS+=-LF:\project\zlib-1.2.11\Release -lzlib
LIBS+= -LF:\project\TAGLIB\taglib\taglib\Release -ltag
LIBS+=-LF:\project\TAGLIB\taglib\taglib\Debug -ltag
LIBS+=-LF:\project\zlib-1.2.11\Debug -lzlibd
and in main.cpp i added:
#include<fileref.h>
#include<tag.h>
#include<QDebug>
and in main function:
TagLib::FileRef f("C:\\Users\\sub\\Downloads\\Mohsen Chavoshi - Sharhe Alef.mp3");
TagLib::String artist = f.tag()->artist();
when i run my application in debug mode,it doesn't run and give me below errors:
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl TagLib::String::~String(void)" (__imp_??1String#TagLib##UEAA#XZ) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: char const * __cdecl TagLib::String::toCString(bool)const " (__imp_?toCString#String#TagLib##QEBAPEBD_N#Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl TagLib::FileName::FileName(char const *)" (__imp_??0FileName#TagLib##QEAA#PEBD#Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl TagLib::FileRef::FileRef(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (__imp_??0FileRef#TagLib##QEAA#VFileName#1#_NW4ReadStyle#AudioProperties#1##Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl TagLib::FileRef::~FileRef(void)" (__imp_??1FileRef#TagLib##UEAA#XZ) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: class TagLib::Tag * __cdecl TagLib::FileRef::tag(void)const " (__imp_?tag#FileRef#TagLib##QEBAPEAVTag#2#XZ) referenced in function main
debug\testTag2.exe:-1: error: LNK1120: 6 unresolved externals
but when i run application in Release mode,the above error are just some Warning and application run with no problem, why this is happening?
thank you.

Compile quazip under windows 8.1 and qt creator

I'm new and trying to use Quazip under qt 5.5. So I just downloaded project sources from http://quazip.sourceforge.net/ and opened .pro file. When I try to build project I 've got multiple errors:
C1083: Cannot open include file: 'zlib.h': No such file or directory
To avoid building zlib on windows I just installed (from here: http://gnuwin32.sourceforge.net/packages/zlib.htm) complete pack for windows in C:\GnuWin32. Then I added this line in .pro file:
INCLUDEPATH += C:\GnuWin32\include
This generated another error:
Cannot open include file: 'unistd.h': No such file or directory
But changing this line
#if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */
into this fixed the problem.
#if HAVE_UNISTD_H
Unfortunately now I get 25 unresolved external symbols, some of them:
quaadler32.obj:-1: error: LNK2019: unresolved external symbol adler32 referenced in function "public: virtual unsigned int __cdecl QuaAdler32::calculate(class QByteArray const &)" (?calculate#QuaAdler32##UEAAIAEBVQByteArray###Z)
quacrc32.obj:-1: error: LNK2019: unresolved external symbol crc32 referenced in function "public: virtual unsigned int __cdecl QuaCrc32::calculate(class QByteArray const &)" (?calculate#QuaCrc32##UEAAIAEBVQByteArray###Z)
unzip.obj:-1: error: LNK2001: unresolved external symbol crc32
quagzipfile.obj:-1: error: LNK2019: unresolved external symbol gzopen referenced in function "private: void * __cdecl QuaGzipFilePrivate::open(class QString const &,char const *)" (?open#QuaGzipFilePrivate##AEAAPEAXAEBVQString##PEBD#Z)
quaziodevice.obj:-1: error: LNK2019: unresolved external symbol deflateInit_ referenced in function "public: virtual bool __cdecl QuaZIODevice::open(class QFlags<enum QIODevice::OpenModeFlag>)" (?open#QuaZIODevice##UEAA_NV?$QFlags#W4OpenModeFlag#QIODevice#####Z)
quaziodevice.obj:-1: error: LNK2019: unresolved external symbol inflate referenced in function "protected: virtual __int64 __cdecl QuaZIODevice::readData(char *,__int64)" (?readData#QuaZIODevice##MEAA_JPEAD_J#Z)
I tries adding this line:
LIBS += -LC:\GnuWin32\lib
But that didn't solve the problem. WHat is the easiest way to use Quazip under Qt?
Download quazip source from quzip site
Open by Qt Creator quazip.pri
Replace all strings #include "zlib.h" or "#include < zlib.h>"
to
#include <QtZlib/zlib.h>
Build project and run unit tests.

How to compile curl 7.35 and use it in project?

I built libcurl and added it to project (specified include directory, library directory and library to use: libcurl.lib/libcurl_imp.lib - I both tried to compile and link static and dynamic library). In both cases (static/dynamic) I faced following:
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_cleanup referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_perform referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_setopt referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>tmp.obj : error LNK2019: unresolved external symbol _curl_easy_init referenced in function "void __cdecl perform(char *)" (?perform##YAXPAD#Z)
1>C:\Users\Public\Documents\Project\curl-7.35.0\Debug\tmp.exe : fatal error LNK1120: 4 unresolved externals
All solutions I found was different variations of "add libcurl.lib".
Now just to clarify my configuration:
dynamic: include directory specified, library directory specified, libcurl_imp.lib specified as additional dependency, libcurl.dll copied to the directory where executable files should be generated.
static: include directory specified, library directory specified, libcurl.lib specified as additional dependency.
using vs2005
Well, it's silly but I was trying to use x64 library in x32 project.

Setting up OpenGL - it won't work

I just bought a new laptop with windows 8 64bit and I am using Visual Studio 2012.
I did the usual procedure with installing a 3d party lib just as I installed them on my previous PCs:
Download freeglut, glew, glfw, glut, sdl
Copy headers into "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include"
Copy libs into "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib"
Copy dll's into "C:\Windows\SysWOW64"
Then I downloaded the project I was developing on my other PC (was developed under windows 8 32bit if that's of any importance) and it would'n compile. The compiler threw me the following linking error:
Error 1 error LNK2001: unresolved external symbol __imp__glDrawArrays#12 - about 50 of these
Error 63 error LNK2019: unresolved external symbol __imp__glClear#4 - again about 50 of these
The project is working perfectly on my old PC.
I did try to make a simple new project: http://pastebin.com/GfEieL6f
Linked the following libraries (Properties->Linker->Input->Additional Dependencies)
opengl32.lib
glut32.lib
glu32.lib
And again it wouldn't compile, again the same linking errors:
Error 1 error LNK2019: unresolved external symbol __imp__glBegin#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 2 error LNK2019: unresolved external symbol __imp__glClear#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 3 error LNK2019: unresolved external symbol __imp__glClearColor#16 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 4 error LNK2019: unresolved external symbol __imp__glColor3f#12 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 5 error LNK2019: unresolved external symbol __imp__glEnd#0 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 6 error LNK2019: unresolved external symbol __imp__glFlush#0 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 7 error LNK2019: unresolved external symbol __imp__glLoadIdentity#0 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 8 error LNK2019: unresolved external symbol __imp__glMatrixMode#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 9 error LNK2019: unresolved external symbol __imp__glOrtho#48 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 10 error LNK2019: unresolved external symbol __imp__glRotatef#16 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 11 error LNK2019: unresolved external symbol __imp__glVertex3iv#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
I don't know if I am missing something, can you give me some ideas ?
PP: I managed to fix the simple program and run it, but I cannot run my old project. Maybe it's a problem because of the platform change ? How can I fix it?
Don't add files to the compiler lib directory. Instead add another library search path to your project.
You probably downloaded library files that aren't compatible with VC++ 2012 and your project build settings. In native code, you can't mix x86, x64, etc. Static libraries need to match your project bitness, not your OS. And Microsoft also changes/extends the library file format, as well as runtime library components used by the library, so you really should get a library file designed for your version of VC++.

File not found main.obj

I have QT installed in my PC, which is using the Visual Studio 2010 compiler
I tested this with a simple hello world application, and it works fine.
However now I am trying to use OpenCV with QT. I have installed Visual Studio 2010 express and professional both, and opencv works fine there. But, when I try to run the OpenCV in QT, I get the following error
main.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate#Mat#cv##QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release#Mat#cv##QAEXXZ)
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree#cv##YAXPAX#Z) referenced in function "public: __thiscall cv::Mat::~Mat(void)" (??1Mat#cv##QAE#XZ)
main.obj:-1: error: LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey#cv##YAHH#Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow#cv##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABV_InputArray#1##Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray#cv##QAE#ABVMat#1##Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?namedWindow#cv##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread#cv##YA?AVMat#1#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function _main
release\FirstProject.exe:-1: error: LNK1120: 7 unresolved externals
Following is my FirstProject.pro file's content
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-26T11:15:33
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = FirstProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include\
LIBS += -LC:\opencv\build\x86\vc10\lib \
-lopencv_calib3d240d.lib\
-lopencv_contrib240d.lib\
-lopencv_core240d.lib\
-lopencv_features2d240d.lib\
-lopencv_flann240d.lib\
-lopencv_gpu240d.lib\
-lopencv_haartraining_engined.lib\
-lopencv_highgui240d.lib\
-lopencv_imgproc240d.lib\
-lopencv_legacy240d.lib\
-lopencv_ml240d.lib\
-lopencv_nonfree240d.lib\
-lopencv_objdetect240d.lib\
-lopencv_photo240d.lib\
-lopencv_stitching240d.lib\
-lopencv_ts240d.lib\
-lopencv_video240d.lib\
-lopencv_videostab240d.lib
I tried by chainging to the following FirstProject.pro content, but no good at all
#-------------------------------------------------
#
# Project created by QtCreator 2013-04-26T11:15:33
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = FirstProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include\
LIBS += -LC:\opencv\build\x86\vc10\lib \
-lopencv_core240 \
-lopencv_highgui240 \
-lopencv_imgproc240 \
-lopencv_features2d240 \
-lopencv_calib3d240
Following is my code
main.cpp
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("D:/Tulips.jpg");
if(!image.data)
{
cout << "Error loading image" << endl;
}
else
{
namedWindow("Image");
imshow("Image",image);
}
waitKey(0);
return 0;
}
Why am I getting this error?
QT Project files try to handle file/directory separators uniformly, ie, forward v's back slashes. It shouldn't matter which is used. However, maybe there's some translation going on.
Try replacing all backslashes '\' with forward versions '/'. Qmake will convert them appropriately.
Replace with -LC:/opencv/build/x86/vc10/lib
It also might be the final backslash on your INCLUDEPATH that's the problem. Maybe it's joining up next line?
I found the answer. The only way to remove the issue is adding the libs one by one, with the complete path
LIBS += C:/opencv/build/x86/vc9/lib/opencv_calib3d240.lib
LIBS += C:/opencv/build/x86/vc9/lib/opencv_contrib240.lib
I had the same problem but I found the answer nowhere. after 8 days trying to fix it finally I found the answer and I want to share it with u.
when u use static linking opencv first check if your libraries are really static linked , to do so open a developer command prompt msvc , navigate into your libraries path , and type the command bellow :
lib /LIBS opencv_world.lib
rather than opencv_world.lib you can put any other library names.
then check there were only refrenced .obj files in it , so that means u can use this library static.
then remember when u use static lib in opencv , u need to at some other libraries to ur project that in dynamic linking u didnt need to. these libraries are in your library directory that their name doesnt start with opencv.
u can see some of them bellow :
IlmImf.lib
ippicvmt.lib
ippiw.lib
ittnotify.lib
libjasper.lib
libtiff.lib
libwebp.lib
zlib.lib
remeber , If u got the error "couldnt find library" , use the exact path to add it. for example :
LIBS += E:\opencv\build-x86-static\install\x86\vc15\staticlib\zlib.lib