C++ erro:undefined reference to `EnumProcesses#12 - c++

I'm trying to get list of running processes with EnumProcesses.
However when I try to compile I receive this exception:
Undefined reference to `EnumProcesses#12'
I'm using eclipse Mingw and XP.
I have tried adding -lpsapi option but it seems not work.
This is code I'm using:
#include <iostream>
#include <windows.h>
#include <psapi.h>
int main() {
DWORD pid[100], bytesr;
EnumProcesses(pid, sizeof(pid), &bytesr);
return 0;
}

Just to clarify as this may be a bit confusing for beginners.
In the case of Qt, you need to add this to your .pro file
win32:LIBS += -lpsapi
another example is to add the kernel32 library to your project, use:
win32:LIBS += -lkernel32
Hope this can help someone

Related

Qt OpenCV programm exits with code -1073741515

What i want to do
I try to use opencv and run a short example program.
Problem
It exits with code -1073741515. I never managed to use openCV on any of the 4 systems i tried, so i do something wrong but don't know what.
I had diffrenet errors using different attempts (undefined reference, crashing programm without error code, etc.), this here is the just simplest example.
What i figured out
Another post told me, that -1073741515 is equal to 0xC0000135 meaning STATUS_DLL_NOT_FOUND.
What i tried
The programm crashes, if include #include <opencv2/core/core.hpp>,
#include <opencv2/highgui/highgui.hpp>and
#include <opencv2/imgproc/imgproc.hpp>. When i comment them out, it runs wnd returns 0 as intended. I don't even need to use anything like cv::Mat or something to make it crash. That seems strange, because the code completion suggests me stuff from openCV, so it somehow sees it. Including #include <opencv2/opencv.hpp> instead leads to the same error code. Including something beginning with opencv (not opencv2) works, for example #include <opencv/cv.hpp>, but has not enough functionality.
Source file
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
int main()
{
cv::Mat InputImage = cv::imread("C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg");
if(!InputImage.empty())
cv::imshow("test", InputImage);
else
cout << "imgage is empty" << endl;
return 0;
}
Project file
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += D:/opencv/build/include
LIBS += -LD:/opencv/build/x64/vc14/lib
LIBS += -lopencv_world343d
LIBS += -lopencv_world343
SOURCES += \
main.cpp
Relevant folders
Include path:
libs:
project:
build (copied the libs to the release/debug folders too):
Versions
QT 5.10.1
MSVC17 64bit Compiler
Windows 7 Enterprise 64bit
openCV 3.4.3 (vc14/vc15)
As Jiu pointed out in the comment above, the solution was simple:
Copy the .dll not the .lib and it works.

Qt <winInet.h> outputs many C4430 & C2146 Errors on build

List of Errors
I think I have included the library for winInet.h in the QT Project file here:
project.pro
QT += qml quick network
CONFIG += c++11
SOURCES += main.cpp \
xmap.cpp
RESOURCES += qml.qrc
LIBS += -lwininet
Everytime I try qmake and build the header file shows many syntax errors and I'm curious if its because I'm wrong in my qt project file syntax.
xmap.h
#ifndef XMAP_H
#define XMAP_H
#include <iostream>
#include <WinInet.h> // <--- ISSUE
#include <Windows.h>
#include <time.h>
class xmap
{
public:
xmap();
// test connection to websites for data
int CheckConnection(int connection = 0);
// pull data from online sources to be evaluated by the model
void RequestAndSaveData(std::string filename);
};
#endif // XMAP_H
Essentially the same as C++ 307 Errors when trying to include winhttp.h in visual studio 2010, except that was using WinHttp instead of WinInet.
Still, same solution: include <Windows.h> before <WinInet.h>.

Portaudio example "record_file.c" does not find "min"

First off, I alread got the smaller example paex_record.c to work.
I use MinGW on Windows8 and did compile portaudio from source, that's were I got the used libportaudio-2.dll from.
I set up a project in QtCreator (without gui) with following .pro-file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
LIBS += -LC:/Audio/patest/paex_record_file -llibportaudio-2
My folder C:/Audio/patest/paex_record_file looks like:
libportaudio-2.dll
main.cpp
pa_ringbuffer.c
pa_ringbuffer.h
pa_util.h
paex_record_file.pro
paex_record_file.pro.user
portaudio.h
I copied both pa_ringbuffer and pa_util to this folder after they were not found.
Main.cppcontains the whole example file paex_record_file.c from the portaudio source.
There is an error when calling the ringbuffer (line 246 and 271: source):
"min" was not declared in this scope
I thought this example would directly run just like the record.c example.
Do I need to include further packages? I've tried algorithm, math, std and using namespace std, but still the error occurs. But I get the feeling it should work out off box, perhaps my include files or folder setup / linkage is not ok?
EDIT: Ok so I just defined a min-function on my own. Now it throws different error:
undefined reference to "PaUtil_GetRingBufferReadAvailable"
and a couple more of this kind. There is probably a lib missing to be linked, having a look...
I also had this linking error trying to compile paex_record_file.c. Turns out you need to compile pa_ringbuffer.c before compiling the main file. There's also an external dependency on some alloc function, so you need to change 2 lines in the file.
I'm not savvy of qt but you need to do something like:
SOURCES += pa_ringbuffer.c main.cpp
Here's how I compile with MinGW:
Changes inside paex_record_file.c
Line 313 : data.ringBufferData = (SAMPLE *) malloc( numBytes );
Line 443 : free( data.ringBufferData );
Compile with MinGW:
gcc -o p_rec.exe C:\path_to_portaudio\portaudio\common\pa_ringbuffer.c \
paex_record_file.c -lportaudio \
-IC:\path_to_portaudio\portaudio\src\common
I didn't get the min problem, but perhaps you can try to remove the ifdef guard and try to recompile.
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#endif
to
#include <windows.h>
#include <process.h>

Application compiles in Eclipse, but has 'undefined reference errors' in Qt

I am building an application that uses mysql and needs a graphical user interface. Because I am more comfortable with Eclipse, and it seems to have better organization and 'pop-up references', I decided to develop the main engine in Eclipse, and transfer it to Qt (using Qt Creator 3.1.2, based on Qt 5.3.1) for the GUI. The engine compiles in Eclipse fine (and a command-line test in Eclipse runs well), but when I include the files in the Qt project, I get undefined reference errors.
I get an error (undefined reference to 'sql::mysql::get_driver_instance') anywhere I have this code:
sql::mysql::MySQL_Driver* driver = sql::mysql::get_driver_instance();
I have all the relevant headers included (since Eclipse sees no problem with it):
#include "mysql_driver.h"
#include "mysql_connection.h"
#include < cppconn/driver.h>
#include < cppconn/connection.h>
#include < cppconn/statement.h>
#include < cppconn/prepared_statement.h>
#include < cppconn/resultset.h>
#include < cppconn/metadata.h>
#include < cppconn/resultset_metadata.h>
#include < cppconn/exception.h>
#include < cppconn/warning.h>
Sounds like a linker error, but I can't find a place to specify linker options in the Qt options page. I'm using the gcc compiler on Ubuntu 14.04.
Am I forgetting to change a setting somewhere or is it something else?
I figured it out, thanks to this thread. Rather than linking in an options page, I merely had to edit the Qt project (.pro) file. I added the following:
LIBS += -lmysqlcppconn
And it now compiles and runs fine. So the problem was simply I didn't understand how to do the linking.

Qt Creator build project - No such file or directory

Sorry to being a noob, but I just moved from Window, Eclipse and Java to OpenSUSE, C++ and Qt Creator, and I met a problem. I am working to create a QGIS application, I have the *.h files in /usr/include/gqis, and *.so files in /usr/lib. I added this line
INCLUDEPATH += /usr/local/include/qgis
at the end of .pro file of project so I can include QGIS library. So far as I coded, everything went smoothly, but when I built the project, Qt Creator threw an error:
qgis.h: No such file or directory
/usr/include/qgis/qgsapplication.h
and it mapped to line 4:
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <qgis/qgsvectorlayer.h>
#include <qgis/qgsapplication.h>
#include <qgis/qgsproviderregistry.h>
#include <qgis/qgssinglesymbolrenderer.h>
#include <qgis/qgsmaplayerregistry.h>
#include <qgis/qgsvectorlayer.h>
#include <qgis/qgsmapcanvas.h>
As far as I searched, I am still unable to solve this problem. Please can anyone help me?
You should do:
INCLUDEPATH += /usr/local/include/qgis
and
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <qgsvectorlayer.h>
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrenderer.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>
Try just:
INCLUDEPATH += /usr/local/include/
Afterall, the qgis is already listed in the #include <qgis/...> path.
I'm using a windows Machine. I'm not sure why this is the case but if you put your project in a shallow directory, the problem might go away. Instead of something like C:\Projects\C++\IntroToDesignPatterns2012\Chapter13\objectBrowser02\objectBrowser02
Try something simple like C:\Projects\objectBrowser02