Code::Blocks (MinGW) compilation error on #include <priority_queue> - c++

I'm using Code::Blocks 17.12 with the default MinGW GCC C++ compiler (with -std=c++11) on Windows 10. I have built several C++ console projects without issues. However, when I include the STL priority_queue class, I get the following error:
fatal error: priority_queue: No such file or directory
#include <priority_queue>
^
compilation terminated.
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
These are my #include directives:
#include <queue>
#include <vector>
#include <priority_queue>
#include <iostream>
Any help would be appreciated.

http://en.cppreference.com/w/cpp/container/priority_queue
Defined in header <queue>

Related

Undefined reference to `mysql_init' , Undefined reference to `mysql_real_connect using MYSQL C++ in codeblock

I added mysql.a in Project->Build Options->Linker Settings->path to mysql.a
I added "include files containing mysql.h" in Project->Build Options->Linker Settings->path to incldue files.
I also added mysql.dll files in debug folder of the project directory.
But still I am getting this error:
||=== Build: Debug in wss4 (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
D:\C++Ws\ws4\wss4\main.cpp|11|undefined reference to `mysql_init'|
D:\C++Ws\ws4\wss4\main.cpp|12|undefined reference to `mysql_real_connect'|
||error: ld returned 1 exit status|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
I am using codeblock 17.12, also tried codeblock 20(latest version) but still getting the same error.
Below is my small code snippet:
#include <iostream>
#include <windows.h>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL* conn;
conn=mysql_init(0);
conn=mysql_real_connect(conn,"localhost","admin","admin","youtube",0,NULL,0);
if(conn){
cout<<"Connected";
}
else{
cout<<"Not connected";
}
}
Please any one show the problem solving steps. It has been taking hours and hours. Thanks

"No such file or directory" C++ header issue

I'm working on a project that has three cpp files and two header files
All my files are in the same folder.
I've been trying to link the header files with the cpp files for the past few days and I'm struggling so much with it.
Firstly, I tried to add the files in Build Options > Search directories > Compiler > Add
Image of my setting in Build options
I've ensured that my header files are typed out properly:
vectorfunc.h
#include <vector>
#ifndef VECTORFUNC_H_INCLUDED
#define VECTORFUNC_H_INCLUDED
//my vector functions declaration
#endif // VECTORFUNC_H_INCLUDED
vectorfunc.cpp
#include <vector>
#include "vectorfunc.h"
#include <iostream>
//my function definitions
TrackKalman.h
#ifndef TRACKKALMAN_H_INCLUDED
#define TRACKKALMAN_H_INCLUDED
void TrackKalman();
#endif // TRACKKALMAN_H_INCLUDED
TrackKalman.cpp
#include <valarray>
#include <vector>
#include <iostream>
#include "vectorfunc.h"
//function definition of TrackKalman()
main.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include "TrackKalman.h"
//main function
Despite all this I still get the error in my compiler:
||=== Build: Debug in RadarScanner (compiler: GNU GCC Compiler) ===|
files\RadarScanner\TrackKalman.cpp -o obj\Debug\TrackKalman.o||No such file or directory|
files\RadarScanner\main.cpp -o obj\Debug\main.o ||No such file or directory|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
I'm using the GNU GCC Compiler
Any help would be greatly appreciated. I can't seem to fix the issue and I definitely don't want to make the whole program in one file.
I think you are missing the
#include "TrackKalman.h”
As first line in TrackKalman.cpp

C++ can't compile when I use iostream (Linux, CodeBlocks)

I want to use C++ Code in Java. I know I have to use JNI. And now I want to compile a shared library in C++ on Linux. I using the Code::Blocks 16.01 IDE and the GNU GCC Compiler.
And now I want to compile this very simple code:
#include <iostream>
void sayHello ()
{
std::cout << "Hello from C++" << std::endl;
}
(I know that I also have to include some more to use this library later in java, but this was just my first test, if it compiles)
The Build log is:
g++ -shared obj/Debug/main.o -o bin/Debug/libnativetest.so
/usr/bin/ld: obj/Debug/main.o: Die Umlagerung von
obj/Debug/main.o: error adding symbols: Ungültiger Wert
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
The Build messages:
||error: ld returned 1 exit status|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
When I just compile the method without#include <iostream> (and sure without cout) it works.
I have tested with another header file like #include <string> and this works.
When I create a project not as a shared library instead a Console Application I can use <iostream>.
I am new to C++ and Code::Blocks therefore if you need some more info please help me where I can find this information.
I do not use Code blocks, so I have no idea how it decided to leave out the fPIC flag. If you try to build it on the command line with
g++ main.cpp -o main.o
The gcc (v5.4 in my case) prompts you to add -fPIC flag, with with the error disappears and the compilation succeeds. fPIC stands for position independent code. i.e., the function addresses (jump addresses) are not hard coded but are left blank. The loader, when it needs the .so, loads it to the memory and then fills the jump addresses dynamically. (-fpic could also work, it is for short jumps, whereas fPIC accommodates also long jumps, i.e., bigger jump ranges at the cost of binary size.)

Error in ld.exe | -lwinmm.lib not found

Hello world!
I am making a simple text based game in CodeBlocks, using C++. Because it would be really boring to play a text adventure with no music, I tried to add a command which is looping music. To be exact, this one:
PlaySound(TEXT("melody.wav"), NULL, SND_FILENAME | SND_ASYNC);
I made sure the melody.wav was in the project's folder, but when I hit play I get the following error:
||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
ld.exe||cannot find -lwinmm.lib|
ld.exe||cannot find -lwinmm.lib|
ld.exe||cannot find -lwinmm.lib|
ld.exe||cannot find -lwinmm.lib|
||error: ld returned 1 exit status|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 6 second(s)) ===|
I tried at first to make a linker flag in the build settings, as I thought this was the problem. The same again! I searched everywhere on Google, but got no proper answer! Please help me! Here is my code:
#pragma comment(lib, "winmm.lib")
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main(){
PlaySound(TEXT("melody.wav"), NULL, SND_FILENAME | SND_ASYNC);// - the correct code
int test = 0;
cin>>test;
return 0;
}
I would be grateful if you could answer on how to get rid of that
ld.exe | cannot find -lwinmm.lib ! :)

osip library sip errors

On the How-To initialize libosip2 site theres program to initialize osip libraries
https://www.gnu.org/software/osip/doc/html/group__howto0__initialize.html
#include <winsock2.h>
#include <Time.h>
#include <stdio.h>
#include <stdlib.h>
#include <osip2/osip.h>
#include <osipparser2/osip_parser.h>
#include <string.h>
int main()
{
int i;
osip_t *osip;
i=osip_init(&osip);
if (i!=0)
return -1;
}
I'm trying to run this code but it doesnt work,
library version 5.0.0
error:
||=== Build: Debug in cos2 (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\emergency\Documents\analizer\cos2\main.cpp|14|undefined reference to `osip_init'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
In order to link with a library, you need to specify it on the command line.
Note that libosip2 produces two libraries and you have to link with both of them in order to use both parser (libosipparser2) and the sip engine (libosip2).
The exact command line depends on the platform, compiler you use and may also differ if you are linking to a static library or dynamic library.
With GCC and dynamic linking, it should be that way:
-L/install-directory-for-libosip2-libs/ -losipparser2 -losip2
-L/install-directory-for-libosip2-libs/ parameter refers to the directory where libraries are available.
this is because you did not link the binary osip.o