libusb not visible in IDE - c++

I m using Code blocks in Ubuntu Linux. I would like to write programs with the library libusb. I have this file in the system, but the complier in the IDE cannot find this file. I add in "build options" this file, it's not help. What is the solution to this problem?
#include <libusb.h>
Update:
dpkg -L libusb-dev shows following:
/.
/usr
/usr/bin
/usr/bin/libusb-config
/usr/include
/usr/include/usb.h
/usr/lib
/usr/lib/libusb.a
/usr/lib/libusb.la
/usr/lib/pkgconfig
/usr/lib/pkgconfig/libusb.pc
/usr/share
/usr/share/doc
/usr/share/doc/libusb-dev
/usr/share/doc/libusb-dev/changelog.gz
/usr/share/doc/libusb-dev/html
/usr/share/doc/libusb-dev/html/index.html
/usr/share/doc/libusb-dev/html/preface.html
/usr/share/doc/libusb-dev/html/intro.html
/usr/share/doc/libusb-dev/html/intro-overview.html
/usr/share/doc/libusb-dev/html/intro-support.html
/usr/share/doc/libusb-dev/html/api.html
/usr/share/doc/libusb-dev/html/api-device-interfaces.html
/usr/share/doc/libusb-dev/html/api-timeouts.html
/usr/share/doc/libusb-dev/html/api-types.html
/usr/share/doc/libusb-dev/html/api-synchronous.html
/usr/share/doc/libusb-dev/html/api-return-values.html
/usr/share/doc/libusb-dev/html/functions.html
/usr/share/doc/libusb-dev/html/ref.core.html
/usr/share/doc/libusb-dev/html/function.usbinit.html
/usr/share/doc/libusb-dev/html/function.usbfindbusses.html
/usr/share/doc/libusb-dev/html/function.usbfinddevices.html
/usr/share/doc/libusb-dev/html/function.usbgetbusses.html
/usr/share/doc/libusb-dev/html/ref.deviceops.html
/usr/share/doc/libusb-dev/html/function.usbopen.html
/usr/share/doc/libusb-dev/html/function.usbclose.html
/usr/share/doc/libusb-dev/html/function.usbsetconfiguration.html
/usr/share/doc/libusb-dev/html/function.usbsetaltinterface.html
/usr/share/doc/libusb-dev/html/function.usbresetep.html
/usr/share/doc/libusb-dev/html/function.usbclearhalt.html
/usr/share/doc/libusb-dev/html/function.usbreset.html
/usr/share/doc/libusb-dev/html/function.usbclaiminterface.html
/usr/share/doc/libusb-dev/html/function.usbreleaseinterface.html
/usr/share/doc/libusb-dev/html/ref.control.html
/usr/share/doc/libusb-dev/html/function.usbcontrolmsg.html
/usr/share/doc/libusb-dev/html/function.usbgetstring.html
/usr/share/doc/libusb-dev/html/function.usbgetstringsimple.html
/usr/share/doc/libusb-dev/html/function.usbgetdescriptor.html
/usr/share/doc/libusb-dev/html/function.usbgetdescriptorbyendpoint.html
/usr/share/doc/libusb-dev/html/ref.bulk.html
/usr/share/doc/libusb-dev/html/function.usbbulkwrite.html
/usr/share/doc/libusb-dev/html/function.usbbulkread.html
/usr/share/doc/libusb-dev/html/ref.interrupt.html
/usr/share/doc/libusb-dev/html/function.usbinterruptwrite.html
/usr/share/doc/libusb-dev/html/function.usbinterruptread.html
/usr/share/doc/libusb-dev/html/ref.nonportable.html
/usr/share/doc/libusb-dev/html/function.usbgetdrivernp.html
/usr/share/doc/libusb-dev/html/function.usbdetachkerneldrivernp.html
/usr/share/doc/libusb-dev/html/examples.html
/usr/share/doc/libusb-dev/html/examples-code.html
/usr/share/doc/libusb-dev/html/examples-tests.html
/usr/share/doc/libusb-dev/html/examples-other.html
/usr/share/doc/libusb-dev/copyright
/usr/share/doc/libusb-dev/changelog.Debian.gz
/usr/share/doc-base
/usr/share/doc-base/libusb-dev
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/libusb-config.1.gz
/usr/lib/libusb.so
But when I change #include <libusb.h> to #include <usb.h> and try to compile this code:
#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
int main(){
usb_init();
printf("Hello world!\n");
return 0;
}
I get the following error:
undefined reference to 'usb_init'

Seems like libusb-dev is missing.
Or
Execute dpkg -L libusb-dev to list all the files in libusb-dev package to find out what is appropriate include file name and it's location. Most likely you will end up changing your include to:
#include <usb.h>
Also, it is not enough just to add a header to the program - you need to show what library should be linked to use those symbols that are declared in the header. Add following to your compiler options:
-lusb

Related

Asio .hpp not found in VSCode, but is included in path

I'm trying to use asio in VSCode with C++. I keep getting the warning:
fatal error: 'asio.hpp' file not found
#include <asio.hpp>
Using the code:
#include <iostream>
#include <asio.hpp>
#include <asio/ts/buffer.hpp>
#include <asio/ts/internet.hpp>
int main(){
asio::error_code ec;
//Create a 'context which is like a platform specific interface
asio::io_context context;
//Get the address of somewhere we wish to connect to
asio::ip::tcp::endpoint endpoint(asio::ip::make_address("93.184.216.34", ec),80);
return 0;
}
In the include path UI settings, I have the following paths listed which should take care of things:
${workspaceFolder}/**
/opt/homebrew/Cellar/asio/**
/opt/homebrew/Cellar/asio/1.24.0_1/include
/opt/homebrew/Cellar/boost/**
/opt/homebrew/Cellar/boost/1.81.0/include/boost
/opt/homebrew/Cellar/boost/1.81.0/include
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include
(there are redundant paths here but I am trying everything at this point)
Finally, it should be able to find the file since the file is there:
ls /opt/homebrew/Cellar/asio/1.24.0_1/include ls /opt/homebrew/Cellar/asio/1.24.0_1/include
Gives:
/opt/homebrew/Cellar/asio/1.24.0_1/include:
asio asio.hpp
I would expect it to just find those files. I have also installed boost using brew. It is available at the boost path included.
I am using Mac M1 with Monterey 12.5.1, and VSCode Version: 1.74.2.
Thanks for the help!
The includePath element in the json file is for intelliSense and not your compiler. If you aren't using CMake you will have to go into tasks.json, there you can specify additional compiler flags.
You want to add a flag: -Ipath/to/asio.

<glad/glad.h>: No such file or directory

I'm following this tutorial to learn OpenGL, but I'm having trouble compiling since the compiler can't find one of the header files.
This is the file I'm trying to compile:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
return 0;
}
To compile, I'm using
$ gcc -o sandbox sandbox.cpp -lGL -lGLU -lglut
and I get the following error:
sandbox.cpp:1:23: fatal error: glad/glad.h: No such file or directory
#include <glad/glad.h>
^
compilation terminated.
I followed the first two sections of this wiki
to install OpenGL and libraries.
I think the problem is either the wrong compile command or a flaw in my OpenGL installation.
GLAD is a function loader for OpenGL. This tutorial explains how to set it up.
The tutorial explains the purpose of GLAD:
Since there are many different versions of OpenGL drivers, the location of most of its functions is not known at compile-time and needs to be queried at run-time.
Setup of GLAD involves using a web server to generate source and header files specific to your GL version, extensions, and language. The source and header files are then placed in your project's src and include directories.
If you are looking at this simple GLFW example you can remove the glad/gl.h include, and the
gladLoadGL(glfwGetProcAddress);
line further down.
If you are on linux, ubuntu for example,
you don't need glad, just add these 2 headers instead:
#include <GLES2/gl2.h>
#include <EGL/egl.h>
If the example is saved as glfw_ex2.c you can compile it at the command line like this:
g++ glfw_ex2.c -lglfw -lGLESv2
Of course, linmath.h must be present in the same directory for this example.
If anything is missing, you can install it like this and try compiling again:
sudo apt install libglfw3-dev libgles2-mesa-dev libegl1-mesa-dev
sudo apt install build-essential
then run it like this:
./a.out

How to install clang header files?

I have clang installed on my MacOS (in /usr/bin/clang ) which I think comes installed by default on Mac, however, when I try to include clang header files in a script, it says they are not found
Example.cpp:1:10: fatal error: 'clang/Driver/Options.h' file not found
Question: is it necessary (and possible, if so, how) to install the header files when clang is already installed and built on the MacOS system (or does clang itself need to be reinstalled at the same time as all the desired development tooling packages and their header files are installed)?
#include "clang/Driver/Options.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/Rewrite/Core/Rewriter.h"
When you use double quotes for including the libraries it will search the current directory which your c/cpp file or application resides in. Try with < and > or compile with the -I option
The question asked if it was necessary and possible to install the header files on MacOS which comes with clang installed already. The desired header files weren't installed and in order to install them it is possible to clone the repo and build llvm and clang (as described in the llvm getting started guide http://llvm.org/docs/GettingStarted.html) , so that it's in effect installed twice on the system.

Working with CLang in c++

I have a compilation error in my program related to the included files, in my program I am including this files:
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
The error message I get when I compile the program using g++ is:
In file included from /usr/include/clang/AST/APValue.h:17:0,
from /usr/include/clang/AST/Decl.h:17,
from /usr/include/clang/AST/RecursiveASTVisitor.h:17,
from FindClassDecls.cpp:2:
/usr/include/clang/Basic/LLVM.h:20:34: fatal error: llvm/Support/Casting.h: No such file or directory
compilation terminated.
I don't have any idea how to solve the problem, and also I am not sure that I installed the CLang library correctly, so can you please tell me how to solve the problem or how to install it correctly on linux (Ubuntu).
It seems that you have the Clang headers installed, but not the LLVM headers (which Clang relies upon). When you are compiling your code, you need to pass the path of LLVM headers with -I to your compiler, as usual.
I'd grab a pre-built Clang+LLVM from the Download page and compile/link against that.
sudo apt-get install libclang-3.8-dev # or libclang-3.9-dev

Missing header files on Mac 10.6.8 stop compilation (SNAP software installation)

I'm trying to install Stanford Network Analysis Project.
I work on MacOS 10.6.8. Yesterday I've downloaded the latest compatible version of Xcode (3.1.4) in order to get the GCC package with a C++ compiler.
When I run the "make" command in my Unix Terminal I get hundreds line of errors.
The first one is about a missing file named "poll.h".
make -C snap-core
g++ -c -std=c++98 -Wall -O3 -I/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys -I/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers Snap.cpp -I../glib-core
In file included from Snap.h:8,
from Snap.cpp:4:
../glib-core/base.h:68:24: error: sys/poll.h: No such file or directory
../glib-core/base.h:75:21: error: netdb.h: No such file or directory
../glib-core/base.h:76:25: error: arpa/inet.h: No such file or directory
I've searched on my hard drive where this "poll.h" file was. I can't find it. I can't find netdb.h or inet.h and a few others either.
These files are not the first ones to be included. I'm saying this to make clear that some files are found but some others are missing. This is what actually happen before I encouter the error:
#include <stdint.h>
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <unistd.h>
#include <signal.h>
#include <sys/poll.h>
As several files are missing I believe I'm missing something big in this issue. Nonethelless I've found out a way to download "poll.h" here. I don't feel comfortable using it... How can I be sure it's the proper file ? What about the other missing files ?
Any suggestion would be really appreciated.
Thanks a lot. Nicolas.