Linker error when linking C++ code with USB driver (ftdi) - c++

I am on a Mac OSX and I am trying to start using the C ftdi drivers I installed using brew
brew install libftdi
That installed the library in the directory /usr/local/Cellar/libftdi/1.2 And I have the following C++ code
#include <iostream>
#include <ftdi.h>
using namespace std;
int main() {
struct ftdi_context ftdi;
ftdi_init(&ftdi);
cout << "Hello World" << endl;
return 0;
}
How should I compile this to make it work? I am including the include/ directory so the compiler can find the header file but I do not know which object file should be linked. I am trying to using the following command
g++ -I /usr/local/Cellar/libftdi/1.2/include/libftdi1/ /usr/local/Cellar/libftdi/1.2/lib/libftdi1.a test.cpp
But I am getting bad linker errors even though I have included the .a file. The lib/ directory has the following contents
cmake
libftdi1.2.2.0.dylib
libftdi1.2.dylib -> libftdi1.2.2.0.dylib
libftdi1.a
libftdi1.dylib -> libftdi1.2.dylib
pkgconfig
Is there something else I should try and link it to? Even if you are not aware of this particular driver is there something in general that I should be doing for drivers like this that I have not done?
Thanks for the help!

Related

Fatal Error: comdef.h: No such file or directory

I installed Aspose.Cells and tried to write a simple C++ file that includes Aspose.Cells.h. I soon realized that I had to install two other external libraries, boost and icu4c as without these libraries my compiler would throw errors saying some h or hpp files can not be found.
My problem is: even after I installed these libraries, I still couldn’t compile my code, as I received a new error saying “Fatal ERROR: comdef.h: No such file or directory.”
And the error persisted even after I installed the latest version for SDK for Win 10.
My simple file can run if I remove the line "#include Aspose.Cells.h" .
Can someone please enlighten me as to how to solve this error?
Also I noticed there is a folder called “Publish” under “include” folder for Aspose.Cells. This folder is besides boost and icu. Could this mean Publish is the third external library to be installed? But I couldn’t find any library called Public on the web. Pls see the screenshot below.
directory of include folder that comes with the installed Aspose.Cells package
Thanks a lot!
My code is as follows:
#include <iostream>
#include <Aspose.Cells.h>
using namespace std;
int main() {
cout << "hello!!!" << endl;
return 0;
}
Regards
Hillary

MingW environment paths

I am trying to compile a simple program but the MingW C++ compiler cannot find the path. I have two files one is C:\main.cpp the other one is C:\Include\test.h
#include <iostream>
#include "test.h"
using namespace std;
int main()
{
cout << "test" << endl;
getchar();
return 0;
}
I have modified the CPATH, CPLUS_INCLUDE_PATH enviroment vars to include the C:\Include path but it still will not compile with g++ c:\main.cpp -o c:\main.exe
Output from command line.
c:\main.cpp:2:18: fatal error: test.h: No such file or directory
compilation terminated.
Also I used this registry file. Still doesn't work.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"
There's not really enough information here, and storing source files in the root is suspect, but you might try:
g++ -I Include c:\main.cpp -o c:\main.exe
Assuming your cwd is C:\
This plus system restart was needed.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"

Using Boost library in XCode

not particularly good with this kind of stuff I have managed to install the Boost C++ library and this basic program works with the g++ compiler and linking to the right .dylib files.
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost;
int main()
{
filesystem::path path1("/Users/username/Documents/testfile.txt");
filesystem::remove(path1);
std::cout << "It worked" << std::endl;
return 0;
}
Now I would like to do the same, just using Xcode to build and run the program, but it doesn't work. I have done everything in this tutorial:
http://buddypanda.com/?p=10
i.e. include header and library search paths, as well as linked the .dylib files of filesystem and system under the 'Build Phases' tab.
The Build succeeds but then the program crashed with an error of EXC_BAD_ACCESS.
I can maybe provide more specifics on what goes wrong if you tell me where to look.
Thanks!
EDIT1: I am using g++-4.9 and Boost-1.58 and Xcode 6.4

Missing cyg*.dll when using libraries compiled with Cygwin, and errors when added

I just compiled zlib and libzip with Cygwin to use them with Code::Blocks in Windows.
My code is that:
#include <iostream>
#include <zip.h>
int main()
{
//Open the ZIP archive
int err = 0;
zip *z = zip_open("main.zip", 0, &err);
zip_close(z);
std::cout << "Hello world!" << std::endl;
return 0;
}
When I build my code, it works well, no errors and warnings.
When I launch my program, it says that I don't have cygzip-2.dll. Okay, I search it and put it in my executable folder. Then, it says that I don't have cygwin1.dll. Okay, I put it too. The same for cygz.dll and cyggcc_s-1.dll.
Oh, it works! But then, my program stops with always the same status: -1073741819.
It doesn't even tell me hello :(
I compiled it with MinGW (it did the same error on Cygwin), and I linked libz.a, libzip.a and libzip.dll.a. Where does the problem could come from?
Thanks!
EDIT: When I try to compile my program IN Cygwin, it says 'undefined reference to '_zip_open'' and 'undefined reference to '_zip_close''. Probably something is missing, but what?
Eventually, I succeeded to use my 2 libraries! I had already tried to use CMake, but failed miserably.
So today, I decided to retry it with the GUI. Firstly, I compiled zlib. I chose the zlib folder, and put the build folder in it. I configured with the option for Code::Blocks and MinGW Makefiles, and native compilers. Then, I opened the .cbp (Code::Blocks Project) in my 'build' folder, and built it.
For libzip, I did the steps except that I specified 2 variables:
ZLIB_INCLUDE_DIR = the root of zlib folder (where there are all the .h and .c) and ZLIB_LIBRARY = [the path to your build folder from zlib]\libzlib.dll
I built it from the .cbp too. And I linked all my files to my project, and it was done!

Compiling and Linking Leda 6.3

I am new to LEDA and I am working on LEDA6.3 Free Edition on OpenSuse 12.1.
As a start I tried to write a simple code "Hello LEDA world" as in the manual http://www.leda-tutorial.org/en/official/ch01s02.html.
#include <LEDA/string.h>
#include <iostream>
using leda::string;
using std::cout;
int main()
{
string msg = "Hello LEDA world!";
cout << msg << "\n";
}
The compilation phase works fine and I generated the .o file.
But they mentioned that this file needs to be linked to the LEDA library and the only library available in the Free edition is the libleda.a and libleda.so
I am trying to link using the following command:
g++ -o welcome welcome.o -L$LEDAROOT -llibleda
What I get is:
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/ld: cannot find -llibleda
I was wondering if someone could help me with how to link my file with the leda library ? so I can get it to run.
Thanks all.
It is unlikely that the library file is called liblibleda.a or liblibleda.so: when the linker sees a an option of the form -l<name> it will search for a library file named lib<name>.so (for shared libraries) or lib<name>.a (for static libraries). You probably just want to use the option -lleda (unless the LEDA developers did something clever and called the library something like libeda.a so you'd use -leda).
Whether this works will also depend on the compiler options being consistent between the installation and your build.