libxl library use in c++ - c++11

When I create a project visual studio 2015 I can work this libxl library hovewer I could not be able to work that library on visual studio qt gui application project.
I try everything whatever I know.
#include "stdafx.h"
#include "QtGuiApplication5.h"
#include <QtWidgets/QApplication>
#include <qapplication.h>
#include <qpushbutton.h>
#include <iostream>
#include <conio.h>
#include "libxl.h"
using namespacenclude <Qt libxl;
using namespace std;
int main(int argc, char *argv[])
{
Book* book = xlCreateBook();
if (book)
{
if (book->load(L"..\\Lab_Bus Datebase.xlsx"))
{
Sheet* sheet = book->getSheet(0);
if (sheet)
{
const wchar_t* s = sheet->readStr(2, 1);
if (s) std::wcout << s << std::endl << std::endl;
}
}
else
{
std::cout << "At first run generate !" << std::endl;
}
book->release();
}
std::cout << "\nPress any key to exit...";
_getch();
QApplication a(argc, argv);
QtGuiApplication5 w;
w.show();
return a.exec();
}
Link2019 error: Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp_xlCreateBookW referenced in function main QtGuiApplication5
link1120 error: Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals QtGuiApplication5 C

You need to configure visual studio project properties to use required lib. Refer this link for the same.
You are using .xlsx file so instead of xlCreateBook use xlCreateXMLBook. Apart from this you need to use using namespace libxl;as well
Below are Factory functions:
Book* xlCreateBook()
Create a binary book instance for xls format. This function should be called first for receiving a book pointer. This function and other classes are in libxl namespace.
Book* xlCreateXMLBook()
Create a xml book instance for xlsx format. This function should be called first for receiving a book pointer. This function and other classes are in libxl namespace.
See below image above code works fine at my machine.

Related

Linking gRPC on Windows for VisualC++

I am trying to use gRPC in a Visual C++ project.
So far I have:
1) Build gRPC with vcpkg: vcpkg install grpc:x64-windows
2) Integrated the vcpgk libraries with visual studio: vcpkg integrate install
So far, so good - intellisense autocompletes the namespace etc.
My client cpp file looks like this:
#include "pch.h"
#include <iostream>
#include <memory>
#include <string>
#include <grpcpp\grpcpp.h>
#include "GRPCServerInterface.grpc.pb.h"
#include "FileFormat.pb.h"
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
using namespace GRPCServerInterface;
int main()
{
std::cout << "Hello World!\n";
// prepare send message & payload
IsFormatSupportedInput msg;
msg.set_fileextension(".asp");
// prepare reply
IsFormatSupportedOutput rpl;
// connect
FileHandler::Stub ClientStub = FileHandler::Stub(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()));
ClientContext context;
// execute rpc
Status status = ClientStub.IsFormatSupported(&context, msg, &rpl);
// handle result
if (status.ok())
{
std::cout << "Format supported says:" << std::endl << "\t formats read: " << rpl.readsupportedformats() << std::endl << "\t formats write: " << rpl.writesupportedformats() << std::endl;
}
else
{
std::cout << status.error_code() << ": " << status.error_message() << std::endl;
}
}
All messages & proto files exits and work in general, since I already use them in python and c# projects.
When building, Visual Studio generates a boatload of 125 errors, all in files I never touched.
In GRPCServerInterface.pb.h, there is identifier GOOGLE_DCHECK is undefined
All other errors are member abc may not be initialized in various header files in the grpc includes, for example
member "google::protobuf::Any::kIndexInFileMessages" may not be initialized in file any.pb.h. Many more in type.pb.h and descriptor.pbp.h.
Last but not least, I get prompted add #iclude "pch.h" to the auto-generated protobuf classes grpcserverinterface.grpc.pb.cc and grpcserverinterface.pb.cc - adding it changes a bit, but basically all errors are still undefined symbol and member may not be initialized. And I really do not want to modify auto-generated code every time.
What am I missing? Or is it just a fruitless endeavor to try using grpc with Visual Studio and should I just move to a build framework like bazel?
Solved it!
Two steps for solving:
1) I disabled precompiled headers for the whole project - this made the #include "pch.h go away. You could probalby get away with disabling it just for the protobuf files, as it can be done on a per-file basis.
2) One of the last errors listed was unresolved external symbol __imp_WSASocketA, which finally led me to this question Unresolved external symbol LNK2019. I just included #pragma comment(lib, "Ws2_32.lib") in one source file, and now everything works just perfect.

Error: unable to open primary document entity

I'm trying to parse an xml file(I've got the schema definition in xsd as well) in my c++ program using xerces library. To get things started I've written a small program, where I just initialise the std::unique_pointer with the xml file. I get the following error if I use an std::string object containing the xml file while initialising whereas the program runs fine if I use the xml file directly for initialisation.
The main program is as follows:
#include <stdio.h>
#include <iostream>
#include "ShDataTypeRel15.hxx"
#include<fstream>
#include<string>
using namespace std;
int main (int argc, char* argv[])
{
try
{
fstream t("/home/vishal/UDA_XML/ShDataTypeRel15.xml", ios::in);
stringstream buffer;
buffer << t.rdbuf();
std::string xml_file = buffer.str();
std::unique_ptr<tSh_Data> Shdata(Sh_Data(xml_file));
}
catch (const xml_schema::exception& e)
{
cout <<"Exception caught"<<std::endl;
std::cerr << e << std::endl;
return 1;
}
return 0;
}
When I replace std::unique_ptr<tSh_Data> Shdata(Sh_Data(xml_file)); with std::unique_ptr<tSh_Data> Shdata(Sh_Data(argv[1])); then the program runs fine(I provide the path to the xml file as command line input.)
I get the following error:
Exception caught
:0:0 error: unable to open primary document entity '/home/vishal/UDA_XML/<?xml version="1.0"?>
The above error statement is followed by the xml file.
Problem was solved after I stored the location of my XML file in the string object instead of the whole content of that XML file in it.
i.e.
Now my std::string xml_file = path_to_xml_file;

basic setup of C++/CLI code so that it can be consumed by unmanaged C/++

I am trying to learn C++/CLI, with the plan of writing a DLL which will be consumed by (unmanaged) C code. However, I cannot get the most basic example to build, as is reproducible below:
I am working in Visual Studio Express 2013.
Create new project -> CLR ->class library
LearnCli.h:
extern "C" __declspec(dllexport)
int __stdcall TestFunc();
LearnCli.cpp:
#include "stdafx.h"
#include "LearnCli.h"
int __stdcall TestFunc()
{
return 3;
}
Build with no problems.
Add Project -> Win32 ->Console Application
From the context menu in solution explorer for the new console project:
Add -> reference -> LearnCli
stdafx.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
#include "..\LearnCli\LearnCli.h"
ConsoleApplication.cpp
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int z;
z=TestFunc();
cout << "Function returns:" << z << endl;
cin.get();
return 0;
}
intellisense has no problems, but on build:
Error 1 error LNK2019: unresolved external symbol _TestFunc#0 referenced in function _wmain [path]\Projects\LearnCli\ConsoleApplication1\ConsoleApplication1.obj ConsoleApplication1
What am I missing which is not allowing the win32 console app to find the function? Cheers.
Edit
Thanks to the comment and link, I have change the LearnCli.h file to
#ifdef LEARNCLIAPI_EXPORTS
#define LearnCliApi_DECLSPEC __declspec(dllexport)
#else
#define LearnCliApi_DECLSPEC __declspec(dllimport)
#endif
And gone to Project -> Properties -> C/C++ -> Preprocessor ->Definitions
and added LEARNCLIAPI_EXPORTS. unfortuately the error is unchanged
You need to link your application(exe) project with the .lib built from dll project.
You can add that from Project settings >> Linker >> Input files or simply put a line on your source.
i.e.
pragma(comment, "lib:<your_lib.lib>")

Debugging file scope in Visual Studio

In Visual Studio 2012, I have this uber-simple C++ program:
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << std::cout;
int i = 1;
return 0;
}
In case you wonder, the "std::cout << std::cout" part is only to show that std:cout can be accessed within the scope of the function - yes, it's meant to print the pointer to the console.
So I set a breakpoint at "int i = 1". When the breakpoint triggers, I want to inspect std::cout from the Command Window (or Immediate Window), so I type:
>Debug.Print std::cout
But it returns the following error:
identifier "std" is undefined
I don't understand why this happens, std should be in the scope of the function which is being executed. The same goes for any other stuff coming from the #include directive, I just can't inspect it using Debug.Print. What do I use in Visual Studio 2012 to inspect EVERYTHING accessible in the execution scope? It seems I can only access local variables with Debug.Print.

opencv with visual studio 2010 error

I am trying to build my first opencv application, I added the include directories and the library directories and then added the linking input which is some opencv.lib files after running this code:
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat im = imread("c:/full/path/to/lena.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
but I got this error:
The program can't start because libgcc_s_dw2-1.dll is missing from your computer.
the error list include:
Warning 1 warning D9002: ignoring unknown option '-static-libgcc' c:\Users\Kato\documents\visual studio 2010\Projects\cvtest\cvtest\cl cvtest
I added -static-libgcc to command line additional options but the same error.

Resources