Lzz (Lazy C++) - #include file not found - c++

I am trying to use Lzz to generate C++ header files from my *.cpp files.
The calling sequence is something like this:
./lzz -hx hpp -c -o out src/*.lzz
Unfortunately, it always fails saying it couldn't find any included headers, including parts of the standard library such as iostream, string and vector.
I get a bunch of error messages like these:
src/CommonIO.lzz:7:10: #include file not found.
src/CommonIO.lzz:8:10: #include file not found.
src/CommonIO.lzz:9:10: #include file not found.
I know I can do give it include paths using the -I parameter:
-I /usr/local/include/c++/4.5.1
but it does not seem to help, because it starts complaining about includes from the standard library:
/usr/local/include/c++/4.5.1/string:40:10: #include file not found.
Could it be caused by the fact that I am running the 32-bit version (binary downloaded from http://www.lazycplusplus.com/download.html) on a 64-bit system (Ubuntu 10.10)?
I have already tried to compile my own Lzz from the source, but It complains about missing rule for making libconf.a:
make[1]: * No rule to make target /home/petmal/Desktop/Downloads/lzz_2_8_2_src/gcc.opt/libs/libconf.a', needed by/home/petmal/Desktop/Downloads/lzz_2_8_2_src/gcc.opt/lzz'. Stop.

Enclose your #includes with
#hdr
...
#end
The delimited lines are copied verbatim to the header file.

Related

Simple C++ compilation error with includes under Cygwin

I've found that a small C++ project, with no dependencies, won't compile under Cygwin with either GCC or Clang. Under Ubuntu there are no problems; and I've been working with this code for a couple of years. I'll introduce a MWE.
The problem arises when including a header in a subdirectory, which itself includes another header, found in that same subdirectory, but specified with the subdirectory in the path provided to the include directive. Executing the following commands can replicate the error:
mkdir foo
echo \#include \"foo/includes.hpp\" > inc.hpp
echo \#include \"foo/bar.hpp\" > foo/includes.hpp
touch foo/bar.hpp
g++ -c inc.hpp
On 64-bit Ubuntu 18.10, the final GCC (or Clang) invocation will produce no errors. On 64-bit Cygwin under Windows 10, the following error message is displayed.
In file included from inc.hpp:1:0:
foo/includes.hpp:1:10: fatal error: foo/bar.hpp: No such file or directory
#include "foo/bar.hpp"
^~~~~~~~~~~~~
compilation terminated.
Can anyone shed some light on the issue? (By the way, I myself do well understand how to properly include header files - this is about the difference between Cygwin and Ubuntu.)
foo/includes.hppshould have local includes if you use "".
That would be:
#include "bar.hpp"
The specification for what paths are used for searching headers is custom for all compilers, although includes with "" should be considered as local for the file where you have the include, not the one that you are compiling.
Basically, it's:
look in the current folder of the current header being processed for a file with that name
use the same paths as <>after
Of course, as I've said, this could change for a new compiler one day. But it is quite safe to assume that this is the behavior for all compilers (What is the difference between #include <filename> and #include "filename"?).

Header files not found even though they are in the right directory?

I'm fairly new to programming using linux so forgive me for any dumb errors I might make in my question but basically I am trying to compile using the terminal (C++) and my code in a .txt file however I keep getting a fatal error that my header file can't be found? When I try to type
g++ -o test main.cpp header.h
I get the error stating "header.h: no such file or directory" in the terminal. I've ensured that both the cpp and header files are in the same directory but no luck there. I've also used
#include <"header.h">
in my main.cpp and header file to try different fixes. I've researched and looked at different answers but no fixes either. Any suggestions?
#include <"header.h">
Use either
#include <header.h>
will lookup the standard include directories for these header files first
or
#include "header.h"
will lookup all include directory pathes specified with the preprocessor options
but don't mix these up.
Also you don't need to specify the header in the compiler command line
g++ -o test main.cpp header.h
# ^^^^^^^^ omit this
That's what the #include statement in your code is for.

GCC compiler cannot find hpp files

I am trying to install the hep-mc library listed here: https://github.com/cschwan/hep-mc for use on compute using the instructions listed in the documentation here: https://github.com/cschwan/hep-mc#installation . To compile one of the example files, I typed this into the terminal:
g++ -L/usr/local/hep-mc/include vegas_mpi_ex.cpp -o vegas_mpi
but I get these error messages:
mpi_vegas_ex.cpp:1:22: error: hep/mc.hpp: No such file or directory
mpi_vegas_ex.cpp:2:26: error: hep/mc-mpi.hpp: No such file or directory
mpi_vegas_ex.cpp:8:17: error: mpi.h: No such file or directory
in the beginning of my code, the declarations are like this:
#include "hep/mc.hpp"
#include "hep/mc-mpi.hpp"
#include <mpi.h>
The tutorial states that I should point the compiler to the location of the "include" folder that contains all the .hpp files, which I have done. Do you guys have any idea as to what I'm doing wrong?
It should also be noted that the compiler cannot find the mpi.h directory even though I have loaded the openmpi module.
-L sets paths where the linker searches for libraries to link. The option you're looking for is -I, which sets the paths where the compiler searches for #included files.
g++ -L/usr/local/hep-mc/include vegas_mpi_ex.cpp -o vegas_mpi
Oops!
g++ -I/usr/local/hep-mc/include vegas_mpi_ex.cpp -o vegas_mpi
-L specifies the path to library files; -I specifies the path to includes.
This is confusing because in terms of project management and distribution, we consider "the library" to include both binaries and header files, as well as documentation and all sorts of goodies. But at a technical level that is not what "library" means.

g++ can't find headers even when it's specified

So basically I have some really simple code that includes <BigIntegerLibrary.hh> which resides in /Users/wen/Projects/include/bigint. I was compiling with this:
g++ main.cpp -o Main -I/Users/wen/Projects/include/bigint
but it reported a fatal error that it could not find the file. Am I doing it right? Thanks!
main.cpp:4:10: fatal error: 'BigIntegerLibrary.hh' file not found
Try
#include "BigIntegerLibrary.hh"
If you specify the #included file with angle brackets (#include <includeFile.h>) the compiler will try to find it in a predefined location whereas if you use #include "includeFile" the compiler first tries the paths you specified with the -I compiler option.
The -I compiler option cannot be used to specify where the <...> files are.
If the path is correct g++ should see the files.
If you use absolute path in include directive, you should change quotation:
#include "/Users/wen/Projects/include/bigint/BigIntegerLibrary.hh"

Creating shared library containing other libraries

i've written a class from that i want to create a shared library. But this class uses other libraries. The call that i use to generate the library is of the form
g++ -fpic -c [necessary *.cpp files] [necessary includes]
Unfortunately this call leads to an error, namely iostream.h: No such file or directory.
But when i build a testfile using the library code it compiles and works properly.
Where might be the problem?
Thanks for your help.
Firstly, I'm pretty sure that you should be using iostream rather than iostream.h so you could try changing that in your source code. E.g.
#include <iostream>
Secondly, you need to check the include directives on the compilation line, as what you're getting is a compilation error indicating that the preprocessor can't find this file. As you haven't listed either your failed or successful commands here, I can't add much more than that.