build error: 'ParseCommandLineFlags' is not a member of 'google' - flags

i am trying to use the google flags on vs2013, my main function is:
int main(int argc, char *argv[]) {
google::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
...
}
and vs2013 reports two build error:
error C2039: 'ParseCommandLineFlags' : is not a member of 'google'
error C3861: 'ParseCommandLineFlags': identifier not found
Anyone can help me ?

I had the same problem between different versions of GFLAGS on different servers, instead of explicitly using google or gflags namespace I used the GFLAGS_NAMESPACE namespace which is defined in gflags/gflags_declare.h, so it will always use the right namespace depending on the installed version.
So you can change this:
google::ParseCommandLineFlags(&argc, &argv, true);
to this:
#ifdef GFLAGS_NAMESPACE
GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
#else
google::ParseCommandLineFlags(&argc, &argv, true);
#end

Related

WinRT too many errors in base.h

I am using Visual Studio and trying to compile simple WinRT example:
pch.h:
// pch.h
#pragma once
#include <Windows.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Web.Syndication.h>
#include <iostream>
ConsoleApplication2.h:
#include "pch.h"
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Web::Syndication;
int main()
{
winrt::init_apartment();
Uri rssFeedUri{ L"https://blogs.windows.com/feed" };
SyndicationClient syndicationClient;
SyndicationFeed syndicationFeed = syndicationClient.RetrieveFeedAsync(rssFeedUri).get();
for (const SyndicationItem syndicationItem : syndicationFeed.Items())
{
winrt::hstring titleAsHstring = syndicationItem.Title().Text();
std::wcout << titleAsHstring.c_str() << std::endl;
}
}
I get "too many errors" in winrt\base.h library file.
What I do wrong and how to compile this simple example?
I guess i found solution.
Visual Studio Menu -> Project -> Manage NuGet Packages -> Browse
install Microsoft.Windows.CppWinRT
Rebuild.

Issue when installing nana in codeblocks

I'm trying to use the nana c++ library for my user interface and i followed this tutorial https://github.com/qPCR4vir/nana-docs/wiki/Code-Blocks-Linux but when i try to compile this code :
#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
int main()
{
using namespace nana;
form fm;
label lb{ fm, rectangle{ 10, 10, 100, 100 } };
lb.caption("Hello, world!");
fm.show();
exec();
}
I get this error : g++: error: unrecognized command line option ‘-nana’
I don't have any idea of what i'm doing wrong. How can i make it works ?
There was an error in the instructions, now fixed
Change -nana to -lnana

Serial Ports in a .DLL file

I have created .dll file in Visual C++.
It includes a function which takes two arguments and send data through serial port. Next i wanted to include this .dll in my application and call these functions. But i am unable to call these functions. Kindly Help.
Here is header file for my .dll
namespace positioncontrol
{
using namespace std;
using namespace System;
using namespace System::IO::Ports;
public ref class control
{
static int rotate(char a, String^ b);
};
}
And here is .cpp for my .dll
#include "goniometer.h"
namespace positioncontrol
{
void control::rotate(char a, String^ b)
{ SerialPort^ serialPort = gcnew SerialPort(L"COM5",9600,Parity::None,1,StopBits::One);
int inp_rotation;
array<unsigned char>^ inp_c = gcnew array<unsigned char>(2);
String^ inp_string;
inp_c[0] = a;
inp_string= b;
inp_rotation=Int32::Parse(inp_string);
inp_c[1] = (unsigned char)inp_rotation;
serialPort->Write(inp_c,0,2);
}
}
I am using this .dll in a desktop application. I have include the header file
#ifndef goniometer_h
#define goniometer_h
#include "goniometer.h"
#endif
Added the path for include directories and added .dll as a reference.
Now i am using the function defined in .dll for a click event
private: System::Void button9_Click(System::Object^ sender, System::EventArgs^ e) {
char dir;
dir = 0x42;
String^ inp_string;
inp_string=enter_degree->Text;
positioncontrol::control::rotate(dir,inp_string);
}
Now when i build my desktop application i am getting following error
1>C:\Users\DELL\Desktop\Final\Motor_Dual_API\Debug\goniometer.h(10): error C2011: 'positioncontrol::control' : 'class' type redefinition
1> c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(530): error C2027: use of undefined type 'positioncontrol::control'
1> c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(530): error C3861: 'rotate': identifier not found
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(540): error C2027: use of undefined type 'positioncontrol::control'
1> c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
1>c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(540): error C3861: 'rotate': identifier not found
Kindly help me in figuring out error.
Thanks and Regards
In C++, the namespace separator is :: rather than .. Check your using statement.
Your code does not define serialPort. Add the definition to the global namespace, to the namespace positionControl or as an auto variable in your function
From the semantic point of view, serialPort is a pointer. So must also create an instance of the object, where serialPort points to.

Error "C3145" and "C2061" in C++ Visual Studio

EDIT: What is C++/CLI? I am programming in Visual studio, and as far as I know using C++... Also, The first error was solved by Peter's comment, but I am still stuck on the second.
I am brand new to the world of C++, and have previously done all my work in Java. I am unfamiliar with the use of pointers and garbage collection (though I believe I understand the concept) and I believe that may be the source of my problems. I am getting the following error messages:
1>Runner.cpp(6): error C3145: 'formOutOfTime' : global or static variable may not have managed type 'System::Windows::Forms::Form ^'
1> may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>Runner.cpp(22): error C2061: syntax error : identifier 'FormOutOfTime'
My code is like this:
PurpleHealth.cpp (This is the file I believe the system calls to start it all off):
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
#include "Runner.h"
using namespace PurpleHealth;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
//Application::Run(gcnew FormOutOfTime());
Runner* runner = new Runner();
//delete runner;
return 0;
}
Runner.h (this is the header file I want to run all my main code, and launch the forms. I also struggle with the purpose behind the header files)
#include "stdafx.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
class Runner
{
public:
Runner();
~Runner();
// functions
private:
void Go();
// member variables
};
And Finally Runner.cpp:
#include "stdafx.h"
#include "Runner.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
//Variable Dclaration
System::Windows::Forms::Form^ formOutOfTime;//Error Here***************************
Runner::Runner()
{
// Do stuff if you need to
this->Go();
}
Runner::~Runner()
{
// Clear memory if you need to
}
void Runner::Go()
{
formOutOfTime = gcnew FormOutOfTime();//Error Here***************************
formOutOfTime->ShowDialog();
}
Please help me solve these messages, and even critique on form is appreciated. Thanks.
managed pointers cannot be declared at static or global scope. They can only be declared at function scope. Move the declaration of formOutOfTime from the top of the runner.cpp file to within the Go method

"seekg identifier not found"

I have a program called main:
#include<iostream>
#include<fstream>
using namespace std;
#include"other.h"
int main()
{
//do stuff
}
and then other.h:
char* load_data(int begin_point,int num_characters)
{
seekg(begin_point);
char* return_val=new char[num_characters+1];
mapdata.getline(return_val,num_characters);
return return_val;
}
and I get the error:
'seekg': identifier not found
why do I get this error and how do I fix it?
seekg is a method from the fstream (declared in istream) class.
You haven't instantiated any.
Take this as an example
ifstream is;
is.open ("test.txt", ios::binary );
// get length of file:
is.seekg (0, ios::end);
source: http://www.cplusplus.com/reference/iostream/istream/seekg/
So, you should
char* load_data(int begin_point,int num_characters)
{
ifstream is;
is("yourfile.txt") //file is now open for reading.
seekg(begin_point);
char* return_val=new char[num_characters+1];
mapdata.getline(return_val,num_characters);
return return_val;
}
Take into account what ParoXon commented in your question.
You should create a file other.cpp containing function's load_data implementation.
File other.h should contain function's load_data declaration. In that file (other.h) you should include all files neccesary for functions declared there to work. And dont forget to protect yourself against multiple includes !
File other.h
#ifndef __OTHER_H__
#define __OTHER_H__
#include <iostream>
#include <fstream>
char* load_data(int,int);//no implementation
#endif
File other.cpp
#include "other.h" //assumes other.h and other.cpp in same directory
char* load_data(int begin,int amount){
//load_data implementation
}

Resources