I am a student currently working on a project to implement Intel Hyperscan for Virus Signature Scanning on Ubuntu 16.04.
On the system, I have gcc 5.4.0 and g++ 5.4.0.
Hyperscan uses CMake to "build" itself.
Having successfully build Hyperscan, I can't seem to be able to find a way to compile my own code for it. I also could not find any "proper" way of compiling code meant for Hyperscan online, hence I assumed g++ would be right. I have tried,
g++ -o -std=c++11 test test.cc $(pkg-config --cflags --libs libhs)
only for it to give the error: hs.h: No such file or directory
Hence I used,
g++ -o -std=c++11 test test.cc -I../hyperscan/src $(pkg-config --cflags --libs
libhs)
to get another error:
/usr/bin/ld: cannot find -lhs and collect2: error: ld returned 1 exit status
At this point, I am kind of lost and can't really progress with my project. Am I using g++ wrongly? Have I built Hyperscan incorrectly? Any tips or solutions would be greatly appreciated!
$(pkg-config --cflags --libs libhs) only works when library and related development files are installed on the system. Looks like you have source code of library, so first you need to build and install library itself, only then compile your test program.
Also, library may be available in standard repositories, then you maybe want to install it using something like "sudo apt install libhs-dev", however, if you have source code of particular version that you need to work with, or library is closed source and non-public, then the only way is to compile and install it manually. Refer to documentation, README, INSTALL files that may be supplied with library code and follow build and installation procedures described there.
Related
I am trying to link GLFW to my C program.
The docs seem to suggest #include<GLFW/glfw3.h> however I have installed 2.7.2 (from my distro's repository) and don't have that header file:
find / -name *glfw* 2> /dev/null
/usr/lib/libglfw.so.2.6
/usr/lib/libglfw.a
/usr/lib/libglfw.so
/usr/lib/pkgconfig/libglfw.pc
/usr/lib/libglfw.so.2
/usr/include/GL/glfw.h
/usr/share/doc/libglfw-dev
/usr/share/doc/libglfw2
/var/cache/apt/archives/libglfw2_2.7.2-1_i386.deb
/var/cache/apt/archives/libglfw-dev_2.7.2-1_i386.deb
/var/lib/dpkg/info/libglfw2.list
/var/lib/dpkg/info/libglfw2.postinst
/var/lib/dpkg/info/libglfw-dev.md5sums
/var/lib/dpkg/info/libglfw2.postrm
/var/lib/dpkg/info/libglfw2.md5sums
/var/lib/dpkg/info/libglfw2.shlibs
/var/lib/dpkg/info/libglfw-dev.list
I tried #include<GL/glfw.h> but I still get undefined reference to 'glfwLoadTexture2D'
How do I link to GLFW and use glfwLoadTexture2D()?
An #include does nothing for the linker; it just brings in declarations, not the actual functions.
The documentation indicates that GLFW uses pkg-config (not surprising; #elmindreda knows her stuff), so your compilation line should be something like:
$ cc `pkg-config --cflags glfw3` -o foo foo.c `pkg-config --static --libs glfw3`
Also note that since the library uses pkg-config, you're not supposed to "care" about details such as where the header and library files are located on your particular installation. Just ask using the --cflags and --libs modes, and you will get the proper locations returned, as the example above indicates.
You are mixing up compilation and linking. If you were missing headers, you would probably have errors a lot sooner than the linking stage.
"Undefined reference" results from symbols not being found by the linker. The most likely cause is you not telling gcc that it should link to the GLFW libraries:
gcc myfile.c -lglfw
When I am on Linux, I compile opengl/glfw projects like this:
gcc main.c -lGL -lglfw
When I am on windows, I compile them by writing:
gcc main.c libglfw3.a -lopengl32 -lgdi32
and I put libglfw3.a file in the same directory where main.c is. I have read people say that they couldn't link properly before writing
-lopengl32 -lgdi32 -luser32 -lkernel32 -lws2_32.
Another thing which may be worth mentioning is that I couldn't link glfw libraries when I downloaded 32bit glfw binaries. When I downloaded 64bit glfw binaries everything worked fine. I have a 64 bit machine and a x86_64-w64-mingw32. I have read comments from people with the opposite experience, where they weren't able to link glfw libraries when they downloaded 64bit binaries, but they were able to link them after downloading 32bit binaries. My advice would be to try both.
I can cross compile a simple C++ program. (ex. g++ -o test test.cpp & arm-linux-gnueabihf-g++ -o test test.cpp).
But when I include OpenCV header files in a C++ program and cross compile it, it throws an error.(ex. arm-linux-gnueabihf-g++ -o ocv_test ocv_test.cpp $(pkg-config --libs --cflags opencv)).
Also I can compile successfully with the default compiler i.e. g++.(ex. g++ -o ocv_test ocv_test.cpp $(pkg-config --libs --cflags opencv))
I executed cmake with
-D CMAKE_TOOLCHAIN_FILE=../platforms/linux/arm.toolchain.cmake \.
as per the opencv docs. That didn't help.
I added opencv include dir in compilation cmd ie -I/path/to/opencv/include and removing pkg-config. That didn't help.
I tried changing arm-gnueabi.toolchain.cmake by exporting PKG_CONFIG_LIBDIR as per suggestion by someone. That didn't help.
I got the following error:
__/usr/lib/gcc-cross/arm-linux-gnueabihf/7/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lopencv_shape
//usr/local/lib/libopencv_stitching.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status__
I want my cross-compiled OpenCV app to run on a RaspberryPI.
I'm confused. Cross compiling OpenCV sources with the -D CMAKE_TOOLCHAIN_FILE option should allow us to cross-compile OpenCV C++ programs. Otherwise we will have to cmake or make (cross-compile) every OpenCV C++ program seperately on a build machine.
I am trying to compile my Qt app from console. Here is specs:
MCBC 3.0 (has preinstalled Qt and gcc), Qt 4.6.4, gcc v4.1.2, qmake v2.01a.
My test qt app contains only 2 files: basket.pro and main.cpp.
basket.pro:
TARGET = basket
TEMPLATE = app
SOURCES += main.cpp
HEADERS +=
main.cpp:
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
return a.exec();
}
I need to compile that app from console.
I got 2 virtual machines. VM #1 has installed QtCreator, and QtCreator compile this app without troubles, also app can be compiled from the console by "qmake" and "make". But there is VM#2, which does not have installed QtCreator, and it is where problems come from.
I tried compile app by commands "qmake make", trying to use Makefile, created by QtCreator, trying to use only gcc comands with explicitly defined paths to Qt libs, include-files and linked libs, but always I got the same errors. For example, I use 2 gcc comands, which used by QtCreator for successful compile this app:
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/lib/qt46/mkspecs/linux-g++ -I. -I/usr/lib/qt46/include/QtCore -I/usr/lib/qt46/include/QtGui -I/usr/lib/qt46/include -I. -o main.o main.cpp
g++ -o basket main.o -L/usr/lib/qt46/lib -lQtGui -L/usr/lib/qt46/lib -lQtCore -lpthread
And so after executing second command I got same error as always:
[root#ARM basket]# ./build_g++_step2
main.o: In function `basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >::data(void) const':
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::QApplication(int &, char **, int)'
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::exec(void)'
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::~QApplication(void)'
/usr/lib/gcc-lib/i586-linux/2.95.4/../../../../include/g++-3/std/bastring.h:152: undefined reference to `QApplication::~QApplication(void)'
collect2: ld returned 1 exit status
Please tell what I missed.
Your GCC compiler is version 2.95 (a much too old version from the previous century, which is not conforming to C++11 standard, and which was known to be quite buggy), since /usr/lib/gcc-lib/i586-linux/2.95.4/is used. Run simply g++ -v or g++ --version to check the version of your compiler. (You could have some PATH issue, or you could have misinstalled your build tools).
You should upgrade your compiler to some much newer version (at least GCC 6 and preferably GCC 7 in july 2017)
BTW, I recommend upgrading also your Qt library. Current version (in july 2017) is Qt5.9 and you should use some Qt5.
Then you need to regenerate your makefile, adding more in QT, as answered by ilbeldus
Notice that you could use pkg-config to help compiling Qt applications (perhaps in your Makefile). You still need to explicitly use moc. For example you might compile some Qt C++ GUI file foo.cc (after having used moc) with e.g.
g++ -Wall -g -c $(pkg-config --cflags Qt5Gui) foo.c
and you would use $(pkg-config --libs Qt5Gui) for link options.
I don't recommend using your old MCBC thing (even with googling I didn't find what that is), notably if it is so obsolete.
You are missing the setup of the QT variable in your .pro file.
Add QT += core gui to it, re-run qmake and try to recompile
See the docs here: http://doc.qt.io/qt-4.8/qmake-variable-reference.html#qt
I want to call gtk+ routines from a C++ program test.cpp, and he encountered a problem while building my program.
I am getting the following error:
g++ test.cpp -o test.x
test.cpp:1:22: fatal error: gtk/gtk.h: No such file or directory
# include <gtk/gtk.h>
Somehow I need to link to gtk+. What will be the correct compiler declarations get my program working.
To compile a program using gtkmm, you need to use the following command:
g++ program.cc -o program `pkg-config --cflags --libs gtkmm-3.0`
The pkg-config --cflags --libs gtkmm-3.0 part provides the include paths and the linker options.
Source: The Flaming Manual, which you should Read.
I'm not sure about gtk in particular but this is a simple file not found issue.
You need to be sure that your system includes search path contains a folder gtk in it which in turn has a file called gtk.h.
Please read about the GCC search paths.
This is also likely a duplicated question so it will probably be closed off soon by the community.
Simple question- are these any way to not have to call libraries during the compiling? I mean, I would like to simply call g++ main.cpp without calling g++ main.cpp -lGL -lGLU -lGLEW -lSTL -lMyMother and so on... I know, makefiles or simple shell scripting, but I would like to make it elegant way - call these libraries inside cpp code - something like 'using GL;'.
Since you're using GCC, you could create/modify a specs file to add the flags you want.
If you don't like typing flags, you really should be using a makefile, though.
Technically you can dynamically load libraries by dlopen() and call functions from it (I am assuming you are on *nix). Though that would be not the same thing and I doubt will make your life easier. Other than that there is no portable way of specifying which library to use in source file.
On Linux you may use pkg-config and shell expansion. Use pkg-config --list-all to discover what packages are known to it (you might add a .pc file to add a new package). For instance, a GTK application mygtkapp.c could be compiled with
gcc -Wall -g $(pkg-config --cflags gtk+-x11-3.0) -c mygtkapp.c
then later linked with
gcc -g mygtkapp.o $(pkg-config --libs gtk+-x11-3.0) -o mygtkapp
Notice that order of arguments to gcc always matter. Of course use g++ to compile C++ applications with GCC.
Consider also using a Makefile like this one. Then just type make to build your software (and e.g. make clean to clean the build tree).
You might use weird tricks in your Makefile to e.g. parse with awk some comments in your C++ code to feed make but I think it is a bad idea.
Technically, you still pass -I and -D flags (at compile time) and -L and -l flags (at link time) to gcc or g++ but the pkg-config utility (or make ....) is generating these flags.
If you edit your source code with emacs you could add a comment at end of your C file to set some compilation command for emacs, see this.
PS. I don't recommend configuring your GCC spec files for such purposes.