sf::Sound functions cause linker errors - c++

I have started to use SFML recently. So I downloaded the 2.4.2 Win64 version of the library and started to play around the examples.
The only problem I have encountered so far is a linker error when I call play/pause/stop on a sf::Sound object. For example for play I get:
main.obj:-1: error: LNK2019: unresolved external symbol
"__declspec(dllimport) public: virtual void __cdecl
sf::Sound::play(void)" (__imp_?stop#Sound#sf##UEAAXXZ) referenced in
function main
Note that I am linking against sfml-audio.lib and can use other objects of the audio lib like AudioBuffers or even other functions of the sf::Sound like setBuffer which is wierd to me.
I am using Qt Creator as IDE so I link in the .pro file like this:
LIBS += -LC:/SFML/lib
CONFIG(release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-network -lsfml-window -lsfml-system
CONFIG(debug, debug|release): LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-network-d -lsfml-window-d -lsfml-system-d
INCLUDEPATH += C:/SFML/include
DEPENDPATH += C:/SFML/include
Does anyone have a clue on whats happening?
Thanks in advance.

Well, finally I solved it just downloading the SFML Master and building the library with CMake + Visual Studio.
The libs/dlls generated that way work flawlessly.

Related

How to resolve 'undefined references' in OpenGL C++ Qt5.5

I have downloaded Earth10 from GitHub and when i compile it in Qt5.3_MinGW with QGLWidget then it works but when i compile it in Qt5.5_MinGW with QOpenGLWidget then it pop up "undefined reference to `_imp__glPolygonMode#8'" etc errors. What can i change in source code to get rid of such errors?
Or if someone can point me to port from QGLWidget to QOpenGLWidget that would also be helpful.
One quick hack for removing all errors was:
CONFIG += c++11
LIBS += -lopengl32
LIBS += -lglu32
LIBS += -lglut32
Add opengl32.lib to the libraries linked by the linker stage.
Paraboloid87 showed the exact code which is required to add opengl32.lib:
Add LIBS += -lopengl32 to your *.pro file.
Thanks for the tip. I'm just "starting" my Qt OpenGL programming experience with QOpenGLWidgets and a call to change the points sizes : calling glPointSize(GLFloat size) caused an undefined reference.
By adding:
CONFIG += c++11
LIBS += -lopengl32
LIBS += -lglu32
LIBS += -lglut32
in the .pro file, the program went thru building and executed in debug mode...showing the vertex points + the colored triangle. Time for more learning....
Again, thanks for the tip.

Using RegOpenKey and RegEnumKey in dynamic QT with MSVC2010

I want to use 2 winapi functions for registry access, as stated.
I have QT 5.3.2 with QT Creator 3.2.0, MSVC2010 build, Windows SDK v7.1 and debugging tools installed.
windows.h is included in my project and both functions are seen, but linker fails with
usb_part.obj:-1: error: LNK2019: unresolved external symbol __imp__RegEnumKeyW#16 referenced in function "bool __cdecl GetUsbName(class QString &)" (?GetUsbName##YA_NAAVQString###Z)
usb_part.obj:-1: error: LNK2019: unresolved external symbol __imp__RegOpenKeyW#12 referenced in function "bool __cdecl GetUsbName(class QString &)" (?GetUsbName##YA_NAAVQString###Z)
I suppose it tries to link those functions dynamically (hense the "__imp"), how can I set it to link against a static .lib file? Or, if that is not possible with dynamically built QT, how do I link those to .dll?
UPD:
Tried these:
LIBS += -ladvapi32
LIBS += AdvAPI32.Lib
LIBS += "c:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\AdvAPI32.Lib"
to no avail
UPD2:
Problem was in QT not recreating makefiles after changes to .pro. After I deleted makefiles, LIBS += -ladvapi32 worked fine. Thought that "Clean project" does that, but it turns out that it doesn't.
You should add to your .pro file
LIBS += -lAdvapi32
or
LIBS += Advapi32.lib
After that run qmake and build again.
[Update] It may be needed to remove generated makefiles manually and recreated them with qmake run again.

Qt 5.3.1 - static building results in linker errors

I just built the static libraries from Qt 5.3.1 for Windows x86 with MSVC 2013. The second step is obviously a static linked application that uses these libraries. So I created a small application (just a MainWindow with some controls, for testing purposes). This is my *.pro-file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = projectname
TEMPLATE = app
CONFIG += static
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
LIBS += -LC:\statics\lib\ -lQt5Core \
-LC:\statics\lib\ -lQt5Gui \
-LC:\statics\lib\ -lQt5Widgets \
-LC:\statics\lib\ -lqtmain \
-LC:\statics\lib\ -lQt5PlatformSupport \
INCLUDEPATH += C:\statics\include
Yeah. This is what I got from several tutorials/my memory from when I worked with 5.1. But when compiling I get those errors:
Qt5Core.lib(Qt5Core.dll):-1: error: LNK2005: "public: __thiscall QString::~QString(void)" (??1QString##QAE#XZ) allready defined in mainwindow.obj.
mainwindow.obj:-1: error: LNK2019: Unresolved extern symbol ""public: static struct QArrayData const * const QArrayData::shared_null" (?shared_null#QArrayData##2QBU1#B)" in Funktion ""public: __thiscall QString::QString(void)" (??0QString##QAE#XZ)".
moc_mainwindow.obj:-1: error: LNK2001: Unresolved extern symbol ""public: static struct QMetaObject const QMainWindow::staticMetaObject" (?staticMetaObject#QMainWindow##2UQMetaObject##B)".
Does somebody know how to handle these errors? Do I have to link against some other libraries not mentioned above, or include some files? I googled this topic and found out that many people experienced the same problem, but they mostly use older versions of Qt oder VS. I also tried to export the project to Visual Studio (working from Qt Creator), but the errors remain.
Thank you for your answers :)
QT += core gui
LIBS += -LC:\statics\lib\ -lQt5Core \
-LC:\statics\lib\ -lQt5Gui \
You are loading both Qt libraries twice: default and custom versions. By default, QT contains both core and gui libraries... you must delete them manually:
QT -= core gui
Just remove LIBS, INCLUDEPATH from project file and run qmake from static build on the project file to create makefile. If this will not help check your PATH

qt creator qt5.1 vs2010 linker error when using static library

i have a problem when i try to use a static library which was compiled with vs2010 in qt creater with qt 5.1.
I'm using qt5.1. which was compiled with/for the vs2010 compiler.
The source for my simple library look as follows:
Lib_Test.h
#pragma once
#include <iostream>
class Lib_Test
{
public:
Lib_Test(void);
~Lib_Test(void);
void HelloTest();
};
Lib_Test.cpp
#include "Lib_Test.h"
Lib_Test::Lib_Test(void)
{
}
Lib_Test::~Lib_Test(void)
{
}
void Lib_Test::HelloTest()
{
std::cout << "Hello World!";
}
This two files are compiled into my "Lib_Test.lib". I copied the lib and the header file to "C:/Qt/" to simplify the library calls.
My qt project file (for a c++ console application):
QT += core
QT -= gui
TARGET = Lib_Test_Qt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:/Qt
DEPENDPATH += C:/Qt
win32:CONFIG(release, debug|release): LIBS += -LC:/Qt/
win32:CONFIG(release, debug|release): LIBS += -lLIB_Test
And finally the main.cpp
#include <QCoreApplication>
#include <Lib_Test.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Lib_Test *lb = new Lib_Test();
lb->HelloTest();
return a.exec();
}
When i try to build the project in Qt Creator i get the following error message
main.obj:-1: Fehler:LNK2019: unresolved external symbol "public: void __thiscall Lib_Test::HelloTest(void)" (?HelloTest#Lib_Test##QAEXXZ) referenced in function _main
main.obj:-1: Fehler:LNK2019: unresolved external symbol "public: __thiscall Lib_Test::Lib_Test(void)" (??0Lib_Test##QAE#XZ) referenced in function _main
debug\Lib_Test_Qt.exe:-1: Fehler:LNK1120: 2 unresolved externals
When i declare the HelloTest method as a static method and try to call it without creating an instance of Lib_Test i get a similar error Message
main.obj:-1: Fehler:LNK2019: unresolved external symbol "public: static void __cdecl Lib_Test::HelloTest(void)" (?HelloTest#Lib_Test##SAXXZ) referenced in function _main
debug\Lib_Test_Qt.exe:-1: Fehler:LNK1120: 1 unresolved externals
What am i missing? Can someboody help? It's really frustrating right now :/.
Edit:
I tried DUMPBIN /SYMBOLS Lib_Test.lib in the msvs2010 console and all i get is:
Microsoft (R) COSS/PE Dumper Version 10.00.40210.01
Copytight (C) Microsoft Corporation. All right reserved
Dump of file Lib_Test.lib
File Type: LIBRARY
Does that mean that my library is somehow empty?? :/
In your qmake files, change
win32:CONFIG(release, debug|release): LIBS += -C:/Qt/ -lLib_Test
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += C:/Qt/Lib_Test.lib
To
win32:CONFIG(release, debug|release): LIBS += -LC:/Qt/
win32:CONFIG(release, debug|release): LIBS += -lLib_Test
Or
win32:CONFIG(release, debug|release): LIBS += -LC:/Qt/
win32:CONFIG(release, debug|release): LIBS += -l_Test
I think one of them should work. And don't forget to go to Build menu, then Run qmake.

How do I use the Boost libraries in a qmake project?

Some days ago I compiled Boost ver. 1.53.0 for VS2012. It works fine, compiles fine. Now I want to use Boost with Qt Creator. In the .pro file I've included
INCLUDEPATH += C:\boost\boost_1_53_0\ -lboost_filesystem
LIBS += C:/boost/boost_1_53_0/stage/lib/
But when I compile I get 2 errors:
:-1: error: cannot find C:/boost/boost_1_53_0/stage/lib/: Permission denied
collect2.exe:-1: error: error: ld returned 1 exit status
What should I do? I've googled but seems I'm the first with this error.
INCLUDEPATH += C:\boost\boost_1_53_0\ -lboost_filesystem
LIBS += C:/boost/boost_1_53_0/stage/lib/
Wrong.
Read this.
Solution:
INCLUDEPATH += C:/boost/boost_1_53_0/
LIBS += "-LC:/boost/boost_1_53_0/stage/lib/"
Boost has complicated library names ("libboost_filesystem-vc90-mt-1_53.lib") and in case of msvc it links them automatically.)
If you want to link additional lib, you do it like this:
LIBS += "-LMyLibraryPath" -lmylib
Where MyLibraryPath is library path, and mylib is library you want to link with.
i'm the first with this error.
The error most likely occurs because compiler tries to open directory as if it were a file or something like that.
win32 {
INCLUDEPATH += C:/Users/User/Downloads/dev/boost_1_61_0
LIBS += "-LC:/dev/Boost/lib/" \
"-Llibboost_filesystem-mgw53-mt-d-1_61.a", "-Llibboost_system-mgw53-mt-d-1_61.a", "-Llibboost_serialization-mgw53-mt-d-1_61.a" -LLIBS
}