Qt DBUS Libraries not loadable if not started from Library-Path - macos

After getting DBUS working on OS X Mavericks after a lot of problems, I have one last problem.
My Apps are not able to interact with the Buses, if i am not in the directory, where libdbus is.
For just making it clear:
The simple program following, that is basically the Widgets-Template, is used for testing:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDBusConnection con = QDBusConnection::sessionBus();
std::cout << "Connection status " << con.isConnected() << std::endl;
}
MainWindow::~MainWindow()
{
delete ui;
}
When running this out of QT Creator, i will get:
Connection status 0
When moving to my lib-Path (it is /opt/local/lib/; installed dbus via ports), and call /path/to/project/executable, i am getting:
Connection status 1
So what I have to do to be able to start my app from every location?

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.

SIGINT was not declared in this scope

Background
I am trying to build a sample REST api app for Rasbian running on Raspberry 3. I used cpprestsdk.
Sample contains the following header file:
#include <condition_variable>
#include <mutex>
#include <iostream>
static std::condition_variable _condition;
static std::mutex _mutex;
namespace cfx {
class InterruptHandler {
public:
static void hookSIGINT() {
signal(SIGINT, handleUserInterrupt);
}
static void handleUserInterrupt(int signal){
if (signal == SIGINT) {
std::cout << "SIGINT trapped ..." << '\n';
_condition.notify_one();
}
}
static void waitForUserInterrupt() {
std::unique_lock<std::mutex> lock { _mutex };
_condition.wait(lock);
std::cout << "user has signaled to interrup program..." << '\n';
lock.unlock();
}
};
}
Issue
When compiling on MacOS, no problem occurs.
When compiling in rasbian however, I get error: 'SIGINT' was not declared in this scope error.
It is clear that SIGINT definition - #define SIGINT 2 or similar - is not reachable when compiling on rasbian.
Question
Why I am getting this error on rasbian but not on macOS? Is it because compiler cannot locate signal.h?
I made sure that include_directories in CMakeLists.txt contains required include paths.
UPDATE
Error resolved when I manually added #include <csignal>.
You haven't included signal.h.
You're including some C++ standard library headers, and as a side effect on MacOS, these happen to include signal.h. However, that isn't specified to happen so you can't rely on it working in different implementations of those headers.
Try adding:
#include <signal.h>
at the top.
On Linux the header file to include is
#include <signal.h>
On MacOS the equivalent header file to include is
#include <csignal.h>
Depending on your OS, header files always change. They should both do the same thing though

error using directory_entry in boost filesystem

I'm starting to use the Boost library in my C++ programs using Code Blocks on Ubuntu.
I encounter a problem while manipulating files, the following code returns a segmentation fault :
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
int main()
{
boost::filesystem::path my_file("/home/malinou/workspace/grunbaum2/grunbaum/Bases/config.txt");
cout << "my_file path : " << my_file.string() << endl;
cout << "my_file exists : " << boost::filesystem::exists(my_file.string()) << endl;
cout << "my_file path : " << my_file.string() << endl;
return 0;
}
I'm using gcc compiler with flags -lboost_system and -lboost_filesystem, and the console output is :
my_file path : /home/malinou/workspace/grunbaum2/grunbaum/Bases/config.txt
my_file exists : 1
Segmentation fault (core dumped)
Process returned 139 (0x8B) execution time : 0.093 s
Press ENTER to continue.
Any idea why my_file seems to cause a problem after calling the exists() function?
(P.S: The problem is the same when I call the is_regular_file() function instead of the exists() one.)
To finally answer my question, it seemed to be a linking error due to the IDE I used. I created a new project with the same files, and it worked perfectly...weird
Anyway, thanks for everyones' help!

How do I handle errors in Lua when executing arbitrary strings?

I'm going for absolute minimalism here. (It's been a while since I've worked with the Lua C API.)
#include <lua.hpp>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv)
{
lua_State* state = luaL_newstate();
luaL_openlibs(state);
string input;
while (getline(cin, input))
{
auto error = luaL_dostring(state, input.c_str());
if (error)
{
cerr << "Lua Error: " << lua_tostring(state, -1) << '\n';
lua_pop(state, 1);
}
}
lua_close(state);
return 0;
}
This program works fine as long as I feed it perfect Lua. However, if I enter something bad (such as asdf()), the program crashes! Why is it not handling my error gracefully?
I've tried breaking out the calls before. It crashes on the call to lua_pcall itself. I never make it past that line.
The binary download (5.2.1 I believe) has a bug that was corrected in 5.2.3. I rebuilt the library from source, and now my program works fine.

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