hypertable library linking problem - c++

i have installed hypertable in /opt/hypertable/current/ and i run an example program from hypertable...
#include <Common/Compat.h>
#include <iostream>
#include <fstream>
#include <string>
#include <Common/System.h>
#include <Common/Error.h>
#include <Hypertable/Lib/Client.h>
#include <Hypertable/Lib/KeySpec.h>
using namespace Hypertable;
int main(int argc, char* argv[]) {
ClientPtr client_ptr;
TablePtr table_ptr;
TableMutatorPtr mutator_ptr;
KeySpec key;
const char* install_dir = "/opt/hypertable/current/";
client_ptr = new Client( System::locate_install_dir(install_dir) );
}
i got this error
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testes.d" -MT"src/testes.d" -o"src/testes.o" "../src/testes.cpp"
../src/testes.cpp:1: fatal error: Common/Compat.h: No such file or directory
i used eclipse CDT for my development and i linked using project Properties->c/c++build->setting->Libraries->LibrarySetPath(-L) and i have inked the HyperCommon also in -l this i set it as /opt/hypertable/current/include/ can any one tell me y i am getting this error...

There are two different paths you need to set when building software: the include path and the library path. You seem to be confusing them.
The include path is the path to find all the .h files. If you have an include path problem, it will manifest at compile time (when building each individual .o file), which is what you are seeing. "Common/Compat.h: No such file or directory" means you are likely missing an include path.
The library path is the path to find the DLL/shared object files at link time. If you have a library path problem, it will manifest at link time (when creating the final executable from the .o files). You are not up to that stage of compilation.
So doing LibrarySetPath and setting -l or -L is a linker/library thing; you want to fix the include path.
Most likely, you want to add /opt/hypertable/current/include/ to the include path (in Eclipse). On the GCC command line, this will be done with -I /opt/hypertable/current/include/, NOT with -L.

you want to add /opt/hypertable/current/include/ThriftBroker/gen-cpp to the include path
你还得一起编译/opt/hypertable/current/include/ThriftBroker/gen-cpp下的cpp文件

Related

Linking a shared library from a large github project

I'm trying to use the following github project https://github.com/apache/parquet-cpp. I was able to build it and the .so files are available in parquet-cpp/build/latest. I copied the .so files(both of libparquet as well as libarrow which had been built) in a separate directory and wrote a simple hello world, simply importing the library as:
#include <arrow/io/file.h>
#include <parquet/api/reader.h>
#include <parquet/api/writer.h>
Now I ran
g++ -Wall test.cpp -L. -lparquet -larrow
However this throws an error as unable to find .h files of arrow/parquet. What am I doing wrong?
You forgot to include the path for the header files in the compilation instruction. You need to find directory containing parquet/api/reader.h and include it in the compilation command
g++ -Wall -I path_containing_header test.cpp -L. -lparquet -larrow
You may include several directories with multiple -I instruction.

Including isolated Qt objects in .cpp file

I want to use a library that utilizes the QT-class QVector2D to calaculate B-splines (library: https://github.com/ejmahler/SplineLibrary). But I can't figure out how to get the includes / linking right using a simple .cpp file and compiling with g++.
This is my attempt
// test.cpp
// My attempt at including the QVector2D class
#include </home/user/Qt/5.8/gcc_64/include/QtCore/qconfig.h>
#include </home/user/Qt/5.8/gcc_64/include/QtCore/qglobal.h>
#include </home/user/Qt/5.8/gcc_64/include/QtGui/qtguiglobal.h>
#include </home/user/Qt/5.8/gcc_64/include/QtGui/qvector2d.h>
// For spline library
#include <SplineLibrary/spline_library/spline.h>
#include <SplineLibrary/spline_library/vector.h>
#include <SplineLibrary/spline_library/splines/uniform_cr_spline.h>
int main()
{
std::vector<QVector2D> splinePoints{
QVector2D( 0, 1),
...
};
UniformCRSpline<QVector2D> mySpline(splinePoints);
QVector2D interpolatedPosition = mySpline.getPosition(0.5f);
}
Compiling with g++ 5
$ g++ -std=c++17 test.cpp -o test
gives
/home/user/Qt/5.8/gcc_64/include/QtCore/qglobal.h:63:28: fatal error:
QtCore/qconfig.h: No such file or directory compilation terminated.
I have verified that the file qconfig.h exists and that it is in the path as included.
I'm guessing my error is either in how I try to include the QT-headers, that I need to link it somehow.
How do I properly include a single Qt component (in this case QVector2D) and compile the project using g++?
First of all, you should never specify absolute paths in you includes. If someone else wants to use your code, they would need to modify all the files to point to the correct headers on their system. Apart from that you're using internal headers that you're not supposed to include yourself. At the very top of the Qt documentation for QVector2D you can find what header you're supposed to include to use the QVector2D class.
So test.cpp should look like this:
#include <QVector2D>
// For spline library
#include <SplineLibrary/spline_library/spline.h>
#include <SplineLibrary/spline_library/vector.h>
#include <SplineLibrary/spline_library/splines/uniform_cr_spline.h>
int main()
{
std::vector<QVector2D> splinePoints{
QVector2D( 0, 1),
...
};
UniformCRSpline<QVector2D> mySpline(splinePoints);
QVector2D interpolatedPosition = mySpline.getPosition(0.5f);
}
Compiler flags
Now, since you have a custom installation path for Qt5.8, the compiler can't find the header in the default search path, so when compiling this file you need to tell the compiler where to search for the Qt headers. As indicated by the line QT += Gui in the documentation I linked above, QVector2D is part of the QtGui sublibrary, so you need to include the headers in the directory /home/user/Qt/5.8/gcc_64/include/QtGui/. The compiler flag to do so is -isystem /home/user/Qt/5.8/gcc_64/include/QtGui.
However, the QtGui headers themselves depend on QtCore headers, but their path is given relative to the /home/user/Qt5.8/gcc_64/include directory, so in order for the compiler to find the header files the QtGui headers depend on you also need to add the compiler flag -isystem /home/user/Qt/5.8/gcc_64/include. Btw this is also the reason why you got the error QtCore/qconfig.h: No such file or directory compilation terminated., there is no such file QtCore/qconfig.h in the directory where test.cpp is located, nor is there one in the system include path, and you didn't give the compiler the additional path where to look for it.
So the compilation should be successful when executing g++ -std=c++14 -isystem /home/user/Qt/5.8/gcc_64/include -isystem /home/user/Qt/5.8/gcc_64/include/QtGui -fPIC -c test.cpp (assuming that the compiler previously didn't have any problem to find SplineLibrarys includes).
Linker flags
The previous command just compiles test.cpp (note the -c flag), but doesn't produce a binary that you can run. The linker has the same problem as the compiler - it doesn't know where to find the precompiled Qt libraries to link against unless you tell it where to look for them. The flag to do so is -L/home/user/Qt/5.8/gcc_64/lib.
In addition to telling the linker where to look for the precompiled libraries, you also need to tell it which ones you're using. As I've mentioned before, QVector2D is part of the QtGui sublibrary, so you need to add -lQt5Gui. Since QtGui depends on QtCore, -lQt5Core also needs to be added.
Assuming you used the default installer, your installation of Qt only includes dynamic libraries, so you also need to tell the linker to store the information where to find the library files in the created binary. The flag you need to add for this is -Wl,-rpath=/home/user/Qt/5.8/gcc_64/lib.
So putting everything together, the final command you need to run is g++ -std=c++14 -fPIC -isystem /home/user/Qt/5.8/gcc_64/include -isystem /home/user/Qt/5.8/gcc_64/include/QtGui -L /home/user/Qt/5.8/gcc_64/lib -Wl,-rpath=/home/user/Qt/5.8/gcc_64/lib test.cpp -lQt5Core -lQt5Gui.
If you use clang instead of gcc, the same command runs just fine if you replace g++ by clang++.

how to compile code using external dll library

I want to compile program with one file test.cpp, which use external library (i have dll and lib). How to do that?
My test.cpp
#include <ExternalLib.h>
#include <iostream>
#include <stdio.h>
#define USE_USB_AUTO_CONNECT 1
int main()
{
printf ("Characters: %c %c \n", 'a', 65);
return 0;
}
ExternalLib is provided by third part company with files: ExternalLib.lib and ExternalLib.dll. There are also files with extension so and a.
When I compile with command:
g++ test.cpp
I get error:
test.cpp:1:20: fatal error: ExternalLib.h: No such file or directory
#include <ExternalLib.h>
Thanks for your help.
I think you are trying to use dll files (compiled in Windows) under Linux, that will not work.
Anyway your error is that the compiler isn't able to locate your header file, to solve this you have several options:
1) Provide the include path when compiling using -I switch
i.e.: g++ test.cpp -I<path to your include directory>
2) Copy the ExternalLib.h to the same directory in which test.cpp lies and use #include "ExternalLib.h" instead of #include <ExternalLib.h>
3) Provide relative path to ExternalLib.h starting from the directory in which test.cpp lies. That is, replace #include <ExternalLib.h> for #include "../../external/ExternalLib.h"
This will solve the No such file or directory problem. Then you will also have to provide the binary/library files using -L (for library path) and -l (for library file) switches.

Undefined reference errors when linking GLFW on MinGW

I am trying to develop an openGL application with GLEW and GLFW on Windows using minGW. In the current directory, project/, I have the directories src/, bin/, and glfw-3.0.4.bin.WIN64/. I have the files test.cpp, glew.h, glew.c, and wglew.h in the src/ directory.
The directory ./glfw-3.0.4.bin.WIN64/include/ contains the GLFW/glfw3.h header file.
The directory ./glfw-3.0.4.bin.WIN64/lib-mingw/ contains glfw3.dll, glfw3dll.a, and libglfw3.a.
My main file, test.cpp contains,
#include "glew.h"
#include "GLFW/glfw3.h"
#include <stdio.h>
int main(int argc, char** argv) {
printf("Hello, World!\n");
glewInit();
glfwInit();
}
I am compiling the program from the project/ directory by running (split into two lines for readability)
gcc -DGLEW_STATIC -DGLFW_DLL -o ./bin/test ./src/*.cpp ./src/glew.c
-I ./glfw-3.0.4.bin.WIN64/include/ -L ./glfw-3.0.4.bin.WIN64/lib-mingw/ -lglfw3 -lopengl32
and I am getting the following error:
undefined reference to `_imp_glfwInit'
I think the problem has to do with me linking the GLFW library incorrectly. From what I understand, including the compiler option -lglfw3 will tell gcc to link ./glfw-3.0.4.bin.WIN64/lib-mingw/glfw3.dll, which contains the definition for glfwInit().
I've looked at solutions to other problems similar to mine and they suggest things such as copying the dll file to the source/binary directories and changing the order of the -l options, but none have seemed to solve the problem for me.
Your problem is that gcc follows strict library naming conventions. It attempts to find glfw3.dll.a, but finds none (because it is named glfw3dll.a - simple rename will fix your problem).
Next step it looks for libglfw3.a, and succeeds - but it is a static library, while reference declared as dynamic in header files (tricky windows DECLSPECs... this problem don't exist on e.g. linux). So, it cannot find _imp__glfwInit, because in static library it is called just glfwInit, so you getting an error.
Removing libglfw3.a is also one of options - in that case gcc will look further and eventually find glfw3.dll and use it.

xerces-c 2.8 : error while loading shared libraries

I'm trying to compile a program running on an HP UX server on a Red Hat Linux.
It uses xerces-c library to parse xml files. Compilation is ok, but when i try to run it, I get the following message
./a.out: error while loading shared
libraries: libxerces-c.so.28: cannot
open shared object file: No such file
or directory
I wrote a very simple program to try and understand whats going on:
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/TransService.hpp>
#include <xercesc/parsers/SAXParser.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
int main(int argc, char* argv[])
{
return 0;
}
And compiled it like this:
g++ test.cpp
-L./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
Surprisingly the file is actually there:
lib]$ ls
libxerces-c.a libxerces-c.so.28 libxerces-depdom.a libxerces-depdom.so.28
libxerces-c.so libxerces-c.so.28.0 libxerces-depdom.so libxerces-depdom.so.28.0
Any thoughts ? I feel i'm missing something, but don't know what.
Thanks in advance.
run ldd a.out and see if the linker can resolve the right .so file
export LD_LIBRARY_PATH to include the current folder (in the same manner as the PATH variable) and check ldd again
the good way to do what you want is the following one:
g++ test.cpp -Xlinker -R ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
or
g++ test.cpp -Wl,-rpath ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
Xlinker or Wl options allow you to use specific linking options, you do not need to modifiy
LD_LIBRARY_PATH
You need to tell the runtime c library where to find the various symbols that arent compiled statically in your code and arent in the usualy /lib and /usr/lib locations.
You do this by adding the path to your shared library to LD_LIBRARY_PATH. In this case, this will be what you have been putting for the -L argument to the compiler.