C++ wxWidgets application not compiling - c++

I am having a problem compiling my wxWidgets program.
#include <wx/wx.h>
#include <wx/url.h>
#include <wx/stream.h>
#include <wx/sstream.h>
int main(int argc, char* argv[])
{
wxURL url(wxT("http://google.com"));
if (url.GetError()==wxURL_NOERR)
{
wxString htmldata;
wxInputStream *in = url.GetInputStream();
if (in && in->IsOk())
{
wxStringOutputStream html_stream(&htmldata);
in->Read(html_stream);
}
wxPuts(html_stream.GetString();
}
}
When I try to compile it, I get the following errors:
main.cpp In function 'int main(int, char**)':
main.cpp 8 error: 'wxURL' was not declared in this scope
main.cpp 8 error: expected ';' before 'url'
main.cpp 9 error: 'url' was not declared in this scope
main.cpp 9 error: 'wxURL_NOERR' was not declared in this scope
main.cpp 12 error: 'wxInputStream' was not declared in this scope
main.cpp 12 error: 'in' was not declared in this scope
main.cpp 15 error: 'wxStringOutputStream' was not declared in this scope
main.cpp 15 error: expected ';' before 'html_stream'
main.cpp 16 error: 'html_stream' was not declared in this scope
main.cpp 18 error: 'html_stream' was not declared in this scope
=== Build finished: 10 errors, 0 warnings ===
What am I doing wrong? Should I be using OnInit() instead of int main(), even if I want the application to be a console, non-gui one?

Take a look into your setup.h file for wxWidgets and be sure that wxURL is #define as
#define wxUSE_URL 1
For more information into your setup file (setup.h), take a look at http://wiki.wxwidgets.org/Setup.H
To take a look at a sample of wxURL, take a look into the your wxWidgets folder, go to "samples" and look into "sockets_client".
There is also reference documents at
http://docs.wxwidgets.org/2.9.3/classwx_u_r_i.html
http://wiki.wxwidgets.org/WxURL
http://wiki.wxwidgets.org/Download_a_file_from_internet

Related

Possible namespace errors in OpenCV header files

I'm just now getting into OpenCV (4.1.0) in C++ (relatively new to both) and I'm getting an odd error from simply including some header files. (GCC 6.3.0)
Error:
from c:\Users\Logan\Projects\Code\C++\webcamTest.cpp:1:
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:697:14: error: 'recursive_mutex' in namespace 'std' does not name a type
typedef std::recursive_mutex Mutex;
^~~~~~~~~~~~~~~
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:698:25: error: 'Mutex' is not a member of 'cv'
typedef std::lock_guard<cv::Mutex> AutoLock;
^~
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:698:25: error: 'Mutex' is not a member of 'cv'
C:\Users\Logan\Projects\Code\C++\Includes\opencv\build\include/opencv2/core/utility.hpp:698:34: error: template argument 1 is invalid
typedef std::lock_guard<cv::Mutex> AutoLock;
Code:
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
int main()
{
return 0;
}
To me this looks like an error with the way the headers are set up, but perhaps I didn't set something up correctly?
Currently the command I'm using is as follows:
g++ -std=c++11 -g -I C:\\Users\\Logan\\Projects\\Code\\C++\\Includes\\opencv\\build\\include -o C:\\Users\\Logan\\Projects\\Code\\C++\\Bins\\<File name I'm using in the editor>.exe <File I'm using in the editor>

error: 'to_string' was not declared in this scope in Windows using cmd

I'm trying compile this code in cmd:
#include <iostream>
#include <string>
using namespace std;
int main(){
int n = 24;
string s = to_string(n);
cout<<s;
}
I found in another qestions, that I should use this command:
g++ -std=c++11 main.cpp
but I get error:
main.cpp: In function 'int main()':
main.cpp:7:24: error: 'to_string' was not declared in this scope
string s = to_string(n);
^
I have latest g++ compiler for Windows v. 5.3.0. I used this installer for MinGW.
I tried solve in to_string is not a member of std, says g++, but this patch doesn't work.
How can I compile this code in command line in Windows?

Algorithm header llrint, llround compiler error

I'm learning C++ and I'm at the point of using the <algorithm> header and I get this compiler error even with an empty project:
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1108:11: error: '::llrint' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1109:11: error: '::llrintf' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1110:11: error: '::llrintl' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1112:11: error: '::llround' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1113:11: error: '::llroundf' has not been declared
/Users/italrolando/hpc-gcc47/bin/../lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/cmath:1114:11: error: '::llroundl' has not been declared
make: *** [algorithm.o] Error 1
Here is the code:
#include <iostream>
#include <algorithm>
using namespace std;
int main( int argc, char ** argv ){
return 0;
}
I'm using Eclipse with GCC 4.7.1 compiler and it's quite strange since the course I'm following is using Eclipse with Gcc 4.7 and it works.
Thanks

FI_Init_FreeType variable declaration error

I am trying to write a simple program that uses freetype.
code :
#include <ft2build.h>
#include FT_FREETYPE_H
int main()
{
FT_Library library;
int error = FI_Init_FreeType(&library);
}
i am compiling as g++ try1_c++demo.cpp -I/usr/include/freetype2
it gives following error:
try1_c++demo.cpp: In function ‘int main()’:
try1_c++demo.cpp:9: error: ‘FI_Init_FreeType’ was not declared in this scope
how do i solve this error?

Googletest compilation errors: ‘xyzTest’ was not declared in this scope

I am learning TDD, using GoogleTest framework. I have successfully built Gtest and have been able to build and run the samples. However, when I tried a simple sample I wrote, I am getting compilation errors.
Here is the source and the build commands I used:
// ################################################
//proj1.h
#ifndef __SCRATCH_PROJ1_H
#define __SCRATCH_PROJ1_H
int addOne(int i);
#endif /*__SCRATCH_PROJ1_H */
// ################################################
//proj1.cpp
#include "proj1.h"
int addOne(int i){
return i+1;
}
// ################################################
//proj1_unittest.cpp
#include "proj1.h"
#include "gtest/gtest.h"
// Test Function
TEST(addOneTest, Positive) {
EXPECT_EQ(1,addOneTest(0)); // <- Line # 24
EXPECT_EQ(2,addOneTest(1)); // <- Line # 25
EXPECT_EQ(40320, addOneTest(40319)); // <- Line # 26
}
TEST(addOneTest, Negative) {
EXPECT_FALSE(addOneTest(-1)); // <- Line # 30
}
GTEST_API_ int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Console output:
g++ -isystem ${GTEST_DIR}/include -pthread -c
/home/user1/scratch/proj1_unittest.cpp
/home/user1/scratch/proj1_unittest.cpp: In member function ‘virtual
void addOneTest_Positive_Test::TestBody()’:
/home/user1/scratch/proj1_unittest.cpp:24:5: error: ‘addOneTest’ was
not declared in this scope
/home/user1/scratch/proj1_unittest.cpp:25:5: error: ‘addOneTest’ was
not declared in this scope
/home/user1/scratch/proj1_unittest.cpp:26:5: error: ‘addOneTest’ was
not declared in this scope /home/user1/scratch/proj1_unittest.cpp: In
member function ‘virtual void addOneTest_Negative_Test::TestBody()’:
/home/user1/scratch/proj1_unittest.cpp:30:5: error: ‘addOneTest’ was
not declared in this scope
Judging from the line numbers in the error messages, it seems that the EXPECT_* macros have not been defined - BUT, I have included gtest/gtest.h in the compilation unit.
What is causing these errors - and how do I fix it?
As it says, addOneTest was not declared anywhere. I'm guessing you meant to call addOne instead.