WlanGetNetworkBssList()-like commands do not compile with g++ - c++

I'm trying to compile a program that prints all available wifi access points including their BSSID.
The example of WlanGetAvailableNetworkList() function on MSDN website compiled just fine when removing the flag part with WLAN_AVAILABLE_NETWORK_CONNECTED.
To print BSSIDs as well I edited that code. I added the following functions and structs:
WlanGetNetworkBssList()
WlanScan()
PWLAN_BSS_LIST
PWLAN_CONNECTION_ATTRIBUTES
PDOT11_MAC_ADDRESS.
All of them except PDOT11_MAC_ADDRESS are marked as 'not declared in this scope'.
My compile command is:
g++ -o WlanAP2 WlanAP2.cpp -lwlanapi -lole32
(The same one worked for the MSDN example.)
My include order is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
What am I missing?
Is there another library to be included?
Why do especially these commands not compile?
Thanks in advance!

Related

Emscripten: algorithm.h file not found

I am trying to compile the following code:
#include<stdio.h>
#include <algorithm.h>
int main() {
printf("hello, world!\n");
return 0;
}
But when I run emcc test.c -o test.html I get the following error:
fatal error: 'algorithm.h' file not found
When I remove the line that imports algorithm.h the code compiles perfectly.
Why is this happening? I was under the impression that algorithm.h was part of the standard library.
Edit:
I changed the name of the file from test.c to test.cpp, I updated the header names to <cstdio> and <algorithms>, and I also set -std=c++11 and it works now.
If this is C++ use
#include <cstdio>
in place of stdio.h and
#include <algorithm>
instead
In standard C++ there is no <algorithm.h> - there is only <algorithm>
Also in C++ the stdio header is both accessible from <cstdio> and <stdio.h> for compatibility.
Also since you are including algorithm the file extension should be .cc or .cpp and not .c or else emcc/gcc will treat it as a C source instead of a C++ one.

c++: How to remove libstdc++.so.6 dependencies

I have 2 program I wrote on my windows computer using Visual Studio 2013. They run fine and work perfectly on my computer, but when I brought them over to my school account that is on a Linux machine, a problem arose. They compile and 1 ran, but the other did not. The one that did not run gave me an error:
.../lib/compat/libstdc++.so.6: version CXXABI_1.3.2 required by...
I have been doing research and I can't seem to find out what in my program would be using libstdc++.so.6, I'm not even really sure what it is or does. Since I am on a student account I can't go installing it using sudo, and it is a homework so I can't submit it using my own libraries.
Any Idea on what my program might be using that would require libstdc++.so.6?
I have 3 files: main.cpp, LinkedList.cpp and LinkedList.h.
I think it might be in main.cpp because I think it stems from a library I am including and main.cpp is the only one that uses outside libraries. Here is the list of libraries it uses:
#include <iomanip>
#include <stdio.h>
#include <fstream>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <bitset>
#include <algorithm>
#include "LinkedList.h"
Thanks in advance!
You are trying to run a program linked against one version of the libraries under another set. That should work fine as long as the library versions aren't too far apart. In your case, the difference between libraries is just too large.
GCC (C++ in particular) has changed quite a bit lately, some programs that used to compile and run fine now blow up or don't compile at all (due to language changes, compiler bugs accepting broken code, ...), and the library ABI has also changed. Your best bet is to carry source code around, and make sure you got compatible language versions on both ends. If that is inconvenient, a solution is to make sure you have the same compiler (and other environment) at both places. The easiest way to get this is to install the same distribution and version.
First you can't remove the dependencies of libstdc++.so.6, because it's a standard C++ library.
To solve your problem you have to check whether your libstdc++.so have the right version
strings /usr/lib64/libstdc++.so.6|grep GXXABI_1.3.1
if there have no matching version, you will have 2 methods like these:
update your gcc on your school's linux OS
yum intsall gcc
download a matching libstdc++.so from this website:
download gcc || download matching libstdc++
then replace the libstdc++.so to /usr/lib64/libstdc++.so.6.*
SOLUTION
I went through a few steps to find my solution. Originally I could compile my program but could not run it.
1) My first step to solve the issue was to change my method of compiling. Originally I compiled my program with the following: g++ main.cpp LinkedList.cpp -o output. I changed it to: g++ -static main.cpp LinkedList.cpp -o output which allowed me to compile and run. This worked but static is a method to dynamically link libraries. This prevents linking with the shared libraries. This is not a good solution because it takes a lot longer and increases the file size of the executable, so I wanted to improve.
2) The second thing I did was remove using namespace std. Yes, I cheated and used it. So I went through my program and added std:: to the appropriate places.
3) The last thing I did was clean up my code. I was using a lot of libraries because my program was a large and complicated program. I was using all of the libraries I had listed in my original post. I went through my code and anywhere I was using a function from a library I would try and write my own code that would do the same thing which would result in my program not depending on those libraries. I was able to replicate a decent amount of these dependent foreign functions with my own which added lot of code, but it allowing me to remove some of these includes. My list of includes is now:
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include "LinkedList.h"
#include <math.h>
I am not sure exactly which step resolved my issue, but now I can compile with my preferred method, g++ main.cpp LinkedList.cpp -o output, and my program runs fine.
I hope this helps someone.

Reusing Slightly Altered Makefile for Slightly Altered Program Gives Error

I made a copy of a makefile that worked for program A for a new program called program B. To keep things simple program B has all of the same include directives as program A. The only changes made to the new makefile are the obvious changes to the list of object files and the name of the created executable. I can also be sure that the compilation error is not caused by anything in main() or any of the functions of program B. Yet somehow I have an error when I use the make command that goes:
/usr/local/triclops/lib/libtriclops.a(triclops.o): In function `triclopsGetDynamicLibPath':
triclops.cpp:(.text+0x198): undefined reference to `dladdr'
In my makeflie I have the following relevant lines:
CPPFLAGS+=-I/usr/local/triclops/include
LDLIBS+=-L/usr/local/triclops/lib
LDLIBS+=-lpgrlibdcstereo -ltriclops -lpnmutils
I appreciate you help, so thanks in advance. I do not know a lot about makeflies, so I am just trying to reuse the code effectively.
EDIT
Both program A and program B have the same include directives
#include "stereoCamera.h"
#include "Aria.h"
#include <iostream>
#include <cstdio>
#include <cv.h>
#include <highgui.h>
#include <cmath>
#include <vector>
#include <opencv2/highgui/highgui.hpp>
Program B can be thought of essentially as this plus an empty int main(){ return0;} while program A does contain much code and has been working for quite some time now.
You could try linking against libdl with -ldl added to your second LDLIBS+= line. You may also need to add the path of libdl.so typically /usr/lib/ to the first LDLIBS+= line.
I cannot answer why program A compiles with the 'same' makefile while program B fails without looking at the programs or the makefiles though.

glPrimitiveRestartIndex could not be resolved

I am learning OpenGL with the Redbooks v8 at the moment. But I'm stuck at the glPrimitiveRestartIndex() function, because it cannot be resolved.
My setup:
OS: ubuntu 14.04,
Compiler: g++ v4.8.4,
Linked GL and glut.
the exact error message is:
error: ‘glPrimitiveRestartIndex’ was not declared in this scope
I included the following libs:
#include <GL/freeglut.h>
#include <GL/glew.h>
enter code here
Any idea why this function could not be resolved?
What additional information is needed to fix this issue?
Minimal test compiles fine:
#include <GL/glew.h>
#include <GL/freeglut.h>
int main(void) {
glPrimitiveRestartIndex(0);
return 0;
}
Compilation line is gcc test.c -lGLEW -Wall.
If you have problems with that minimal example - then something is fundamentally wrong with your setup, but I bet it isn't the case. If it is, please let me know.
If it compiles but your code doesn't - then it is a mistake in your code, either include order or defines (both direct #define and -D compiler flags).

When I submit it online, they always says compile errors

That's my code:
It works good on my mac.
But I'm not sure is that the problem of Gcc version or not.
they said the sstream and string header are wrong.
1779655.134485/Main.c:8:19: fatal error: sstream: No such file or directory
compilation terminated.
here is the hint
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
You are trying to include C++ header file in your C program.
Gcc is C compiler.
You need to rename Main.c to Main.cpp and use g++ compiler...