Include local library - arduino

I'm trying to copy a couple of libraries I created to my local sketch folder, as instructed in the Arduino Library Tutorial
My folder structure is the following
Documents\Arduino\MySketch\
MySketch.ino
libraries\
Timer\
Timer.h
Timer.cpp
I get the following error
fatal error: Timer.h: No such file or directory
#include <Timer.h>
Note that this works just fine if I move my libraries to the C:\Program Files (x86)\Arduino\libraries folder, but I really don't want to keep them appart from my source since I can not check them to my git repository.
I think I'm following the instructions given in the tutorial precisely. I just googled about this and found several similar problems, but no solution. It's supposed to be working in recent versions of the IDE (I'm on 1.8.5 on Windows 10).
I also tried to include the libraries using double quotes instead of angle brackets but I got the same error.
Can you please let me know how to fix this problem?
Thanks

Recent versions of the Arduino IDE do recursive compilation of the src subfolder of the sketch folder. So to achieve your goal, you will want a folder structure that looks something like this:
MySketch
|_MySketch.ino
|_src
|_Timer
|_Timer.h
|_Timer.cpp
Then the #include directive in the sketch should look like this:
#include "src/Timer/Timer.h"
It's quite common for Arduino libraries to use incorrect syntax for their internal #include directives. For example, Timer.cpp might contain this line:
#include <Timer.h>
That doesn't cause a problem when the library is installed normally but it will cause an error when you try to use the library bundled with a sketch. The solution is to edit the library to use the correct syntax:
#include "Timer.h"

It seems to me that the solution looks fine if libraries/Timer is used only by this sketch. What if you have several projects {git_repo}/sketch_{n}/sketch_{n}.ino calling the same class Timer(.h, .cpp) ?
If you want to avoid code duplication (and you do), then you may put them into {git_repo}/libraries/. You will still be able to check them out into git. However, this is painful because it requires that each time you modify one file into the library, you need to :
delete the dir C:\Program Files (x86)\Arduino\libraries\Timer
reload the ".zip" (from {git_repo}/libraries/Timer) from the Arduino IDE
Very painful.
What you could do is create a symbolic link from {git_repo}/libraries/your_library to C:\Program Files (x86)\Arduino\libraries\your_library
On Ubuntu that would be :
cd ~/Arduino/libraries/ # where Arduino stores the libs
rm -rf Timer/ # deleting your library if exists
ln -s ~/dev/code/[MY_PROJECT]/libraries/Utils/Timer Timer
The Arduino IDE will know your library exists, and would recompile it automatically if Timer.{h,cpp} (from your git_repo) was modified in between.

Related

Error when adding include folder cmake

I am creating new project using cmake to configure it. That project has dependency of library lib1, for example which is compiled separately.
Problem starts when I add include folder of the lib1 like this:
include_directories (../lib1/include)
When I launch make command it complains saying that
fatal error: 'QSharedData' file not found
#include < QSharedData >
QSharedData is included in one of the .h of lib1.
How can I fix this?
Thanks in advance
You should definitely follow Qt's cmake instructions (https://doc.qt.io/qt-5.10/cmake-manual.html) and use their cmake package, i.e.
find_package(Qt5Core)
...
The Qt cmake package takes care of determining and setting the needed include directories, etc.

How to prevent absolute paths in dynamic linker

I have a solution with various projects, one of which is the main executable, and the rest are libraries the executable depends on. Each one compiles and links fine. However, trying to start the executable gives weird results. Using ldd, I see that the executable is trying to find libraries like so:
../bin/debug/libBlahBlah.so => not found
However, for each project, I'm declaring "bin/debug" (which is the output directory for these libraries) as a libdirs entry, and linking against the library by adding "BlahBlah" as a link, where "BlahBlah" is the name of the project.
I'm not even sure how to accomplish this without premake. Any help is appreciated.
The original intention was to have the library sit next to the executable then set an RPATH that searched for the library next to executable. With the way it is now, it searches for that absolute path relative to the executable... I cannot figure out how to get it off.
I'm using premake5. I've tried to use the nightly and compiling myself. Upstream is currently not compiling however.
If you are using the latest alpha or source of Premake5, you can use the "RelativeLinks" flag to use -L/-l instead of relative paths to libraries:
project "MyProject"
flags "RelativeLinks"
You will still need to set up the rpath properly though; you can do that with buildoptions() and the appropriate command line flags for your compiler. Maybe (untested):
buildoptions "-Wl,-rpath=."
That should work in Premake 4 as well.

IAR Embedded Workbench cannot find files, Pe1696, even though it is searching for them

I am using IAR Embedded workbench 5.51 for MSP430. I am using C99.
I am trying include code from a third party library. I have copied the directory structure of this third party library exactly within a sub-directory in my main project directory. However, when I try to compile I get a bunch of
Fatal Error[Pe1696]: cannot open source file "ThirdPartyLib/Subdir/file.h"
However in the log IAR shows:
searched: "C:\ ... bla bla bla ... \Source\ThirdPartyLib\Subdir\"
The include statements in each of the source files in this library are all like:
#include "ThirdPartyLib/Subdir/someheader.h"
I have attempted to add the path to the C preprocessor by going to:
Project -> Options -> C/C++ Compiler -> Preprocessor
and adding the lines:
$PROJ_DIR$\ThirdPartyLib\
$PROJ_DIR$\ThirdPartyLib\Subdir\
$PROJ_DIR$\ThirdPartyLib\Utils\
I do not have "Multi-file Compilation" checked.
All of the source files in question have been added to the project. I have created groups to mimic the directory structure of the library.
The problem goes away if I change the paths from absolute paths to relative paths such as
#include "somelocalheader.h"
#include "../Utils/someotherheader.h"
But I am dealing with a large number of files and want to modify them as little as possible.
I have never had an issue with this before - does anyone have any idea why this would happen. Is there a simple fix for this so I do not have to scrub every include statement in every c file?
This is essentially what my directory tree looks like:
Source
Debug
Exe
Output.d43
List
blabla.map
Obj
...
Release
...
settings
...
ThirdPartyLib
Subdir
... Third Party Code Files Live Here ...
Utils
... More Third Party Code Files Live Here ...
... My Code Lives Here, Along with the EWP, EWW, etc ...
EDIT #2:
I moved the directory of ThirdPartyLib up a level, because I run doxygen recursively on /Source/ and I realized that it takes doxygen FOREVER, and plus the library has its own API.
Anyway, here is what the structure looks like now:
Working Copy
Source
Debug
Exe
Output.d43
List
blabla.map
Obj
...
Release
...
settings
...
... My Code Lives Here, Along with the EWP, EWW, etc ...
ThirdPartyLib
Subdir
... Third Party Code Files Live Here ...
Utils
... More Third Party Code Files Live Here ...
I have added a group back to my project for ThirdPartyLib with two subgroups SubDir and Utils, and added all of the files from the Subdir and Utils directories to the corresponding subgroups.
Now I have tried to compile this again, and again i am faced with the Pe1696 errors. IAR says:
searched: "C:\...\Working Copy\ThirdPartyLib\SubDir"
Yet it is still not finding the files.
I referred to this post:
http://e2e.ti.com/support/low_power_rf/f/155/t/110195.aspx
I am not sure it is completely relevant, because the directories I am including don't seem to have 'fallen out'. IAR is clearly searching for the files.
But I tried anyway to add the following lines to the preprocessor
$PROJ_DIR$\..\ThirdPartyLib\SubDir
$PROJ_DIR$\..\ThirdPartyLib\utils
This does not seem to help. I get these additional lines in the message log:
searched: "C:\...\Working Copy\Source\..\ThirdPartyLib\SubDir\"
searched: "C:\...\Working Copy\Source\..\ThirdPartyLib\Utils\"
Edit #3
I tried moving the EWW/EWP up a level to "Working Copy" and then readded all of the groups and all of the files... no dice. I am lost here. The part that is most frustrating is that the same library is implemented in another project that was done by some former developers and I am trying to include it the same way. I know this is going to be something trivial, I just don't know what.
If all of the #include references inside the library are of the form #include "ThirdPartyLib/Subdir/file.h", then the root directory where ThirdPartyLib is located should be in the preprocessor include path.
If your directory structure is:
C:\My Project\Source
\ThirdPartyLib
then C:\My Project would be expected to be in the preprocessor include path.
When the compiler searches for include files it will join in turn, each of the include search paths with the path listed in the #include directive until a matching file is found.

include external libraries (from a subdirectory of the source-code-folder) in qt

I am a bit confused by the way qt handles libraries. My plan was to put the external libraries I need into the source directory, so that a do not have to install them into the system. As this doesn't seem to work (see below) I was wondering, if this is generally a bad idea or if there is some trick to it??
So I compiled the libraries and put them into /mysubdir. In the .pro-file I added
LIBS+= -L"mysubdir" -l"mylib"
I got the compiler error [projectname] Error 2 and don't know what it means.
The argument passed to -L must be an absolute path. Please give it a try with a full path, or at least -L./wcslibc. Though I'm not sure whether ./ will be recognized correctly. You can get the current path in qmake like this:
LIBS += -L$${PWD}/wcslibc -lwcs

Enabling JPEG support for QImage in py2exe-compiled Python scripts?

I'm trying to use a JPEG image in a QImage object from a Python script, with PyQt4.
The script itself works perfectly, the image loads and can be manipulated and rendered and all. However, when I try to "compile" this script with py2exe, everything works but the JPEG image. Replacing it with a PNG equivalent works, but since my program downloads images from the web, they won't always be in PNG format and I can't afford converting them all with another library.
I've discovered that JPEG image support for QImage, along with other image formats, is provided by some DLLs in the \qt\plugins\imageformats directory (they're called qjpeg4.dll and qjpeg4d.dll). I think I need to use them somehow in my executable, but I don't know how. I've tried simply copying them to my exe directory, no luck. I've tried, as indicated here, to include those files as data_files in the setup.py script, but no luck (it looks like all it does is copying these files to the exe's directory, so it changes nothing from copying them manually anyway).
I'm sure there's a handful of applications out there using PyQt with JPEG images, how do they do it? It seemed like a trivial task but I'm stuck on it now.
Also, I want my app to be cross-platform (why else would I be coding in Python?), I hope I won't run into such packaging trouble (it's not the only one) when packaging for OS X or Linux. Will I?
After hours of stumbling around with the same issue, I’d like to share the solution that worked for me on windows vista:
using python2.6
copy the following directory into your dist directory generated by py2exe:
C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats
I just dropped the imageformats directory directly into my dist directory, without any further modifications to qt.conf or anything like that. I haven’t tried it, but this may work for phonon as well.
I'll have to confess I never managed to get the py2exe + pyqt combination quite right (and, py2exe doesn't help at all with cross-platform packaging). PyInstaller seems to be much better -- the docs at http://www.pyinstaller.org/ are old, but the svn trunk is much more recent. Some docs are in slides given at the recent Pycon Italia Tre conference -- http://www.pycon.it/static/stuff/slides/distribuire-programmi-python-con-pyinstaller.pdf -- and, the slides are in English, and contain the current maintainer's email, so they should help! (And, let's all lobby the current maintainer to update the docs...!-)
Try adding a qt.conf file to your exe's directory, to tell qt where to find binaries and plugins.
Something like the following works for the simple case, where you just dump all dll's in the same dir as the exe:
[Paths]
Prefix = .
Plugins = .
Update: Then copy your plugins-contents (the imageformat/sqldriver directories etc) to the exe dir. I don't think you can load plugin dlls from the same directory as the exe. See Qt plugin doc for details on plugon subdirectories. (Or, leave out the 'plugins = .' and copy the plugins dir to the exe dir, so you have /plugins/imageloaders/qjpeg4.dll).
Etienne -- Thank you for the tip. After much reading and trial-and-error, I arrived at the same conclusion: use PIL to show jpegs in a py2app-generated app.
http://www.thetoryparty.com/wp/2009/08/27/pyqt-and-py2app-seriously-i-dont-know-what-to-do-with-you-when-youre-like-this/
What I guess is that the proposed solutions for py2exe/Windows don't necessarily apply to py2app/OSX.
I'm on OSX Leopard.
Let's suppose you have an application MyApp.app.
Put the libraries libqjpeg.dylib and libqgif.dylib in
MyApp.app/Contents/plugins/imageformats/
Put this in qt.conf in MyApp.app/Contents/resources/:
[Paths]
Prefix = .
Binaries = .
On my machine (Leopard) this works.
After trying all the above solutions in vain, I just ended up using PIL to load my images. Since I wanted to convert these images to a texture in an OpenGL Qt widget, the result was the same whether I load the image using Qt or PIL. Still, I'm baffled that such a basic thing as loading JPEGs is so complicated in a GUI library as well-known and widely used as Qt.
I had the exact same problem. Fixed it using this : http://mail.python.org/pipermail/python-list/2008-June/669374.html
Copy Qt plugins to the directory: $YOUR_DIST_PATH/PyQt4/plugins;
Copy qt.conf to your dist directory;
Edit qt.conf, change Prefix to ./PyQt4
For me, the problem was solved just copying the "qt.conf" for the directory of the executable.
You can find the "qt.conf" in ...\PythonXX\Lib\site-packages\PyQt4\qt.conf.
Thanks for help.
Everything above failed for me until I realized that I was bundling the .exe (that is, I had the option "bundle_files" : 2 in my setup.py. I changed it to bundle_files = 2, and now it works great.
The above solutions are fine. Specifically, I just added the following line in my setup.py:
data = [ ("imageformats", glob.glob("C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats*.dll")) ]
(in addition to other files, of course).
Then, the image loading dlls are in MY_EXE_DIR/imageformats
I didn't need a qt.conf to make this work, though I'm sure you could use it if you want to keep your directory tree less cluttered.
It is possible to use the JPEG plugin with a py2exe'd script, even using bundle_files. You need to arrange two things to get this to work properly:
Copy PyQt4/plugins/imageformats to the output directory of py2exe (default: dist)
You only have to copy the formats you actually need.
When use the bundle_files option you need to execlude the Qt dll files from the
zipfile using the --dll-excludes option for pyexe.
You still have to copy the Qt DLLs to the output directory some other way (such as
by using the data_files option).
on windows, suggested solutions work perfectly.
however, on osx can't make it work even with instructions here above.
question is: the libqjpeg.dylib and libqgif.dylib files are located in the /Developer/Applications/Qt/plugins/imageformats/ directory, and that if you have installed Qt itself, not just PyQt. these files do not work for me.
in PyQt distribution, i see the files libqjpeg.bundle and libqgif.bundle in /opt/local/libexec/qt4-mac/plugins/imageformats/, however these are not libraries, and btw i cannot open their contents either, even if they have the .bundle extension. using these files instead does not work either.
i am curious to know what have you done to make it work on osx. i have installed PyQt following this guide.
Thanks for your helpful answers for the question! I have encountered same problem as you did and no solutions could help. Hopefully, I was using VCS and found that old version of my app loaded JPEG images correctly and new versions stopped doing it. I caught this bug using PySide v1.2.2.
To enable libraries loading, I used the same solution as #Macke did (i.e. added and edited qt.conf).
My qt.conf was next:
[Paths]
Binaries = .
Plugins = qtplugins
C:\Python27\Lib\site-packages\PySide\plugins directory was copied to qtplugins directory, so I had next directories:
qtplugins\accessible
qtplugins\codecs
qtplugins\graphicssystems
qtplugins\iconengines
qtplugins\imageformats
I had next code:
class NotesCalendar(QtGui.QCalendarWidget):
note_icon = QtGui.QImage("res/16note.png")
Moving class variable NotesCalendar.note_icon to constructor solved the problem and Qt started loading its libraries correctly. Seems that class variable constructor interrupted some internal PySide stuff.
It works with no problems on Windows. Specifying correct qt.conf and copying plugins directory is enough to enable JPEG support in py2exe + PySide build. Of course, you must have no problems in your own code.
I hope this will save someone a day! ;)

Resources