How to include hidapi in makefile? - c++

how should properly include HIDAPI library?. After installing from the Fedora 20 repositories. It is installed in /usr/lib
This is my makefile:
CC=g++
CCFLAGS= -Wall -O0
SOURCE= Main.cpp ModuloUsb.cpp ModuloUsb.h
EXEC=modulo
test:$(SOURCE)
$(CC) $(CCFLAGS) $(SOURCE) -I../hidapi `pkg-config --libs --cflags libusb-1.0` -o $(EXEC)
After make command:
Any suggestions??

Related

Manjaro Linux cannot open source file "gtkmm.h"

I have been trying to set up my coding environment for GUI development in c++ recently, with little success. I use Manjaro Linux with Visual Studio Code, but for some reason, I always seem to get include errors when including files that I know are there.
Most recently, I tried to set up gtkmm-4.0 by installing the package and the documentation. I double checked in /usr/include/ to ensure the packages were all present, but I still am getting include errors:
cannot open source file "gtkmm.h" and
gtkmm.h:No such file or directory
At this point, all the code I have is:
#include <gtkmm.h>
#include <iostream>
int main(int argc, char* argv[]){
return 0;
}
Makefile:
exec = game.out
sources = $(wildcard src/*.cpp)
objects = $(sources:.cpp=.o)
flags = -g $(shell pkg-config gtkmm-4.0 --cflags)
libs = $(shell pkg-config gtkmm-4.0 --libs)
$(exec): $(objects)
g++ $(objects) $(flags) -o $(exec) $(libs)
%.o: %.cpp include/%.h
g++ -c $(flags) $< -o $#
install:
make
cp ./game.out /usr/local/bin/game
clean:
-rm *.out
-rm *.o
-rm src/*.o
I have scoured the internet for answers, but everything I found was either for a different os/environment or just didn't
#Galik and #John helped me solve this!
What I had to do was use g++ src/main.cpp -o main $(pkg-config gtkmm-4.0 --cflags --libs) to compile my code, then run the executable.
Thank you both for your help and guidance!!
You need to install pkg-configand add this to the compiler flags in your Makefile:
flags = -g $(shell pkg-config gtkmm-2.4 --cflags)
libs = $(shell pkg-config gtkmm-2.4 --libs)
# ...
$(exec): $(objects)
g++ $(objects) $(flags) -o $(exec) $(libs)
The tool pkg-config has a database of the correct paths for supporting libraries.
Depending on your version if gtkmm, you may need to substitute gtkmm-3.0, if you have version 3.0.

Adding a library

I'm doing some modifications to an existing project which is pretty big, so it's built with the autotools. The modifications involve the Ibex library, so I've added an #include "ibex.h" in one of the source files. The library is properly installed on my system, I have the following files:
/usr/local/lib/libibex.a
/usr/local/include/ibex/ibex.h
/usr/local/share/pkgconfig/ibex.pc
Results of the pkg-config commands:
$ pkg-config --libs ibex
-L/usr/local/lib -libex -lprim -lClp -lCoinUtils -lm
$ pkg-config --cflags ibex
-frounding-math -ffloat-store -I/usr/local/include -I/usr/local/include/ibex
The original Makefile.am corresponding to the compil unit I want to get to use ibex, is as follows:
noinst_LTLIBRARIES = liblrasolver.la
AM_CPPFLAGS=$(config_includedirs)
liblrasolver_la_SOURCES = LAVar.h LAVar.C Delta.h Delta.C LRASolver.h LRASolver.C LAArray.h LAArray.C LARow.h LARow.C LAColumn.h LAColumn.C
if WANT_LIBRARY
include_HEADERS = Delta.h LAArray.h LAColumn.h LARow.h LAVar.h LRASolver.h
endif
I modified it this way:
noinst_LTLIBRARIES = liblrasolver.la
AM_CPPFLAGS=$(config_includedirs) `pkg-config --cflags ibex`
AM_LDFLAGS=`pkg-config --libs ibex` -lblas -llapack
liblrasolver_la_SOURCES = LAVar.h LAVar.C Delta.h Delta.C LRASolver.h LRASolver.C LAArray.h LAArray.C LARow.h LARow.C LAColumn.h LAColumn.C
if WANT_LIBRARY
include_HEADERS = Delta.h LAArray.h LAColumn.h LARow.h LAVar.h LRASolver.h
endif
Came to this modification by looking into the generic Makefile provided along with ibex sources to compile ibex projects:
SRCS=$(wildcard *.cpp)
BINS=$(SRCS:.cpp=)
CXXFLAGS := $(shell pkg-config --cflags ibex)
LIBS := $(shell pkg-config --libs ibex) -lblas -llapack
ifeq ($(DEBUG), yes)
CXXFLAGS := $(CXXFLAGS) -O0 -g -pg -Wall -frounding-math
else
CXXFLAGS := $(CXXFLAGS) -O3 -DNDEBUG -Wno-deprecated -frounding-math
endif
all: $(BINS)
% : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $# $< $(LIBS)
clean:
rm -f $(BINS)
Ok, autoreconf works, as well as ./configure (though its output never talks about "ibex" which I find suspicious already). But make fails. Doesn't find the header:
../../../src/tsolvers/lrasolver/LRASolver.h:38:18: fatal error: ibex.h: No such file or directory
#include "ibex.h"
You're not using pkg-config correctly. You should use the PKG_CHECK_MODULES macro, see for reference https://autotools.io/pkgconfig/pkg_check_modules.html (full disclosure: I wrote that.)
You're also using AM_LDFLAGS incorrectly since libraries are not ldflags. You should use _LIBADD.

Issue Linking Box2D application on OS X

I have an SDL game I have been working on as my first somewhat real project. I decided to introduce Box2D physics as I was not happy with the collision detection. So I installed it to /usr/local/lib/Box2D and in the folder is Box2D.h and supporting folders. I am using MacVim to code on OSX 10.9.2 to develop, and clang++ compiler from the command line.
In my game code I am just trying to create a simple world to test things out:
#include <Box2D/Box2D.h>
.......
world = new b2World(b2Vec2(0.0,9.81));
My make command finds the library, but errors out trying to build.
$ make clean && make
rm -rf obj bin
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Ball.cpp -o obj/Ball.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Game.cpp -o obj/Game.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Paddle.cpp -o obj/Paddle.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/TextureManager.cpp -o obj/TextureManager.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/main.cpp -o obj/main.o
clang++ -framework SDL2 -framework SDL2_image -F /Library/Frameworks -L/usr/local/lib/Box2D obj/Ball.o obj/Game.o obj/Paddle.o obj/TextureManager.o obj/main.o -o bin/game
Undefined symbols for architecture x86_64:
"b2World::b2World(b2Vec2 const&)", referenced from:
Game::init() in Game.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [game] Error 1
And here is my Makefile. Box2D is in /usr/local/lib/Box2D/Box2D.h. I am pretty sure my issue is somewhere in the Makefile.
CXX = clang++
CXXFLAGS = -Wall -c -std=c++11 -I/usr/local/lib
SDL = -framework SDL2 -framework SDL2_image
LDFLAGS = $(SDL) -F /Library/Frameworks -L/usr/local/lib/Box2D
SRC_DIR = src
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
OBJ_DIR = obj
OBJECTS = $(subst $(SRC_DIR)/, $(OBJ_DIR)/, $(patsubst %.cpp, %.o, $(SOURCES)))
#$(warning $(OBJECTS))
BIN_DIR = bin
EXE = game
# run these no matter what
.PHONY: all clean run
all: $(EXE)
$(EXE): $(OBJECTS)
#mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $(OBJECTS) -o $(BIN_DIR)/$(EXE)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
#mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) $< -o $#
clean:
rm -rf obj bin
run:
./$(BIN_DIR)/$(EXE)
It does not appear that you ever actually link the Box2D library anywhere? You use -L to specify directories to search while linking, but I don't see a -l option to actually link the Box2D library (whatever it's called).
Your output line seems to bear this out:
clang++ -framework SDL2 -framework SDL2_image -F /Library/Frameworks -L/usr/local/lib/Box2D obj/Ball.o obj/Game.o obj/Paddle.o obj/TextureManager.o obj/main.o -o bin/game
You need to get -lbox2d (or whatever the correct name for the Box2D library is) in there.

Creating a makefile for opencv project

I am trying to run a opencv c++ project from ubuntu. I ve installed properly the opencv, I ve managed to run a simple opencv cpp file. I am trying to run my MSVC++ code. I put in the same file cpp and header files. I ve created the following makefile:
CC=g++
CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
executable: program.o Detection.o prediction.o
$(CC) -o executable $(LIBS) program.o Detection.o prediction
program.o:
$(CC) $(CFLAGS) -c program.cpp
Detection.o:
$(CC) $(CFLAGS) -c Detection.cpp
prediction.o:
$(CC) $(CFLAGS) -c prediction.cpp
I am receiving fatal error: core.hpp: No such file or directory
compilation terminated. Any idea for what I ve got to do??
Not a solution, but several marks about your makefile:
'prediction.o' on linkage line (maybe a wrong copy-paste)
I am not sure but it is not recommanded to put space when initialize your variables CFLAGS and LIBS
It is not necessary to precise source compilation
CC=g++
CFLAGS=pkg-config --cflags opencv
LIBS=pkg-config --libs opencv
executable: program.cpp Detection.cpp prediction.cpp
$(CC) program.cpp Detection.cpp prediction.cpp -o executable $(LIBS) $(CFLAGS)

Problem using yaml-cpp on OS X

So I'm having trouble compiling my application which is using yaml-cpp
I'm including "yaml.h" in my source files (just like the examples in the yaml-cpp wiki) but when I try compiling the application I get the following error:
g++ -c -o entityresourcemanager.o entityresourcemanager.cpp
entityresourcemanager.cpp:2:18: error: yaml.h: No such file or directory
make: *** [entityresourcemanager.o] Error 1
my makefile looks like this:
CC = g++
CFLAGS = -Wall
APPNAME = game
UNAME = uname
OBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
mac: $(OBJECTS)
$(CC) `pkg-config --cflags --libs sdl` `pkg-config --cflags --libs yaml-cpp` $(CFLAGS) -o $(APPNAME) $(OBJECTS)
pkg-config --cflags --libs yaml-cpp returns:
-I/usr/local/include/yaml-cpp -L/usr/local/lib -lyaml-cpp
and yaml.h is indeed located in /usr/local/include/yaml-cpp
Any idea what I could do?
Thanks
Your default target is "mac" and you have rule how to build it. It depends on object files and you do not have any rules how to build those, so make is using its implicit rules. Those rules do just that:
g++ -c -o entityresourcemanager.o entityresourcemanager.cpp
As you can see there is no -I/usr/local/... part here.
The easiest way to fix that is to change CPPFLAGS and LDFLAGS value globally:
YAML_CFLAGS := $(shell pkg-config --cflags yaml-cpp)
YAML_LDFLAGS := $(shell pkg-config --libs yaml-cpp)
SDL_CFLAGS := $(shell pkg-config --cflags sdl)
SDL_LDFLAGS := $(shell pkg-config --libs sdl)
CPPFLAGS += $(YAML_CFLAGS) $(SDL_CFLAGS)
LDFLAGS += $(YAML_LDFLAGS) $(SDL_LDFLAGS)
mac: $(OBJECTS)
$(CXX) -o $(APPNAME) $(OBJECTS) $(LDFLAGS)
CPPFLAGS value is used by implicit rules that build object files from cpp files, so now compiler should find yaml headers.
Edit:
LDFLAGS probably should go after OBJECTS
Don't you mismatch your include directory?
-I/usr/local/include
instead of
-I/usr/local/include/yaml-cpp