Create utility like Linux "df", based on source code of this utility - c++

In university a have task - find source code of utility df, and using it code - create my own simple utility like df.
But then I simply tried to compile source code of it (file df.c) from (for ex) this site - gcc compilation has errors with library and a lot of other errors..
On first step - when I do:
gcc -o df.out df.c
I have this error:
df.c:21:20: fatal error: config.h: no such file.
But in /usr/lib folders in my pc there is this file. What's wrong? Or what is another way to create my own df utility?

problem to me is to understand what are doing in code of df.c, because
there are using SUCH lots of constants, functions and 'define'
variables from many headers.
The very site you mention above has hyperlinks to the definitions everywhere in the code, so you can quickly navigate wherever you need to.

Related

how do I create files on sciTE for c++?

I am newly learning c++. I am using the Linux ubuntu operating system and a sciTE text editor.
Do you know how to create a file on scite that I will be able to compile and then create an archive on terminal? also how do I create a 'make file. cpp'. Any help will be greatly appreciated.
Thanks! :)
Do you know how to create a file on scite that I will be able to compile and then create an archive on terminal?
You can use any text editor to write C++ source code. There is nothing very editor-specific about it. The file itself should be assigned a name that your compiler will recognize as designating a C++ source file. Compilers generally look at the filename extension for that purpose, and ".cpp" is a very common pattern recognized as indicating C++ source. It looks like that's what you're intended to use, so when you save the file just be sure to give it a name that ends in .cpp.
In order to successfully compile, you of course need to write valid C++ source code in the file, and in order to compile it to a program (I assume that's what you meant by "archive") it must contain a valid main() function.
how do I create a 'make file. cpp'.
I think you've gotten your instructions confused. Perhaps the instruction is just meant to convey what I already said about giving your source file a name ending in ".cpp". Alternatively, you may have been asked to create a makefile, which is input to the build tool "make", that could be used to build the program instead of running the compiler directly. You may ask specific questions about make here, but we are not in the business of writing full tutorials. The first thing you should do if you need instructions about make would be to consult your course materials and lecture notes, and / or ask your instructor.
On the third hand, make doesn't even need a makefile in some simple cases. It may be that you are instructed to build the program without a makefile. If you have named the source "prog.cpp" and it contains valid C++ source for a complete program, then you should be able to build that program via the command "make prog". In that case, the resulting program will be named "prog".

How can I compile c++ to multiple files?

I have a program (cpp) with many classes. Every class is in separate source file (.h + .cpp).
How can I split the compiled program into multiple files (instead of one big executable file)?
Let's say, one file for every class (same as the code structure).
So that every time there is change in a specific class, I compile only that class, and replace the specific compiled file related to that class.
(Something similar to .DLL files in Windows.)
Example from real life:
I am making TUI interface for managing mysql.
I would like to create mysql text editor (TUI) with ncurses.
the code (class) for creating and managing single window object is in
'textWin.cpp' + 'textWin.h'
the code (class) for managing multiple windows, by creating windows objects from previous class is in winMan.cpp winMan.h
the code (class) for managing mysql database is in :
mysql.cpp mysql.h
and so on...
so, I have the following files:
MyProgram.cpp
- winMan.cpp + winMan.h
- textWin.cpp + textWin.h
- mysql.cpp + mysql.h
- ..
- ..
After g++ compilation, I get one executable file, './MyProgram' (size about 15Mb.) which I deliver to all my customers (1000's of them).
I Just found a typo in textWin.cpp, I fixed it, and I told to all customers that there is an update... all of them need to download one big 15Mb file, this consumes allot of bandwidth and server resources, for just a small update.
Is there a way to send to all my customers smaller file, that contains only the compiled code for textWin class ?
I use g++ on Centos7
The gcc compiler will happily take a list of cpp files to compile together to make one executable. You don't need to write a "containing" cpp file. However, you still have the issue that each time it rebuilds them all.
The alternative is to build each sourcefile separately to an object file, then link those all together. Hopefully each of those invocations of the compiler will add up to less time than the single command-line. But how to keep track of which cpp files actually need to be rebuilt?
The usual approach is to use a makefile and a make utility which will check the dates of all the mentioned files. There are a variety of flavours of makefile, and helper makefile engines. Download a simple package like gzip and you can quickly get an idea of how the Makefile is structured. Then there is lots of help online, or you may decide that this is just too much trouble for a project with 5 files in it.
As suggested in the comments by #RSahu
Shared Libraries (.so files) is the way to split your compiled code.
here is a small example:
https://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html
Of course, you could put your texts into separate text-files and only deploy those in the an error is there. For your special use case, where binary differences must be deployed, this question might be helpful: How do I create binary patches?
Another option, do proper versioning. That way, your customers might be able to decide for themselves. That is, if they need this update.

Generating working CHM files using Doxygen and GraphViz (Invalid .hhc file?)

I'm in the middle of documenting my C++ GUI library and I just started using Doxygen. I've got two test files that are documented now, but I have problems when trying to generate the CHM help files. Doxygen runs without error, and dot appears to be functioning correctly to generate images.
However, it appears the resulting .hhc, .hhk, and .hhp files are broken in some way. index.hhc and index.hhk are exactly the same and running 'hhc index.hhp' does not work. It returns an error :
HHC6000: Error: An internal file could not be created. Make certain there is enough disk space on the drive where you are compiling your file.
HHC5007: Error: Fatal navigational compilation error. This is likely the result of an invalid contents (.hhc) file.
I have uploaded a zip file of my two test sources, the Doxyfile generated by the Doxy Wizard, and the .hh* files created by doxygen.
http://members.allegro.cc/EdgarReynaldo/temp/test1.zip
Both HTML Help Workshop and GraphViz are on my path.
Do I need to change a setting in the doxyfile? How do I fix this?
Regards, bugsquasher
EDIT
After taking albert 's advice, everything seemed to magically work. Nothing was really different though.

Trying to access a string from a website c++

I've been trying to figure this out for the better part of the day, but due to my lack of knowledge of c++ and libraries, I've made little progress.
I'm trying to access a page that contains a single string, and basically read it.
I've attempted to use curl to access the internet, but I can't seem to be able to get it working. Then I came across this post that has a simple enough solution (post). I downloaded the zip file from the cpp-netlib link, extracted it to a folder containing a .cpp file with the provided code, and ran the g++ command. This is the error it's giving me:
testing.cpp:1:50: fatal error: boost/network/protocol/http/client.hpp: No such file or directory
Any idea what I can do? (for what it's worth, this code is meant to be cross-compiled and run on an omega-2 eventually).

vim Syntastic not finding header files when developing with mbed

I'm developing a prototype using ARM's mbed OS. I'm newish to C++ so having syntastic working would be ideal, but it gets hung up on the import of "mbed.h".
The structure of the project is:
/
myfile.cpp
mbed-os/
mbed.h
Syntastic is saying fatal error: 'mbed.h' file not found.
How can I get Syntastic / GCC (or whatever it's using) to find the header files?
UPDATE:
Looks like including a .syntastic_cpp_config file with the following in is helping (but involved an absurdly painful process of add a line, run Syntastic, find the next missing header file):
-Imbed-os
-Imbed-os/cmsis
-Imbed-os/cmsis/TARGET_CORTEX_M
-Imbed-os/cmsis/TARGET_CORTEX_M/TOOLCHAIN_GCC
-Imbed-os/drivers
-Imbed-os/events
-Imbed-os/features
-Imbed-os/hal
-Imbed-os/platform
-Imbed-os/rtos
-Imbed-os/targets
-Imbed-os/targets/TARGET_NORDIC/TARGET_NRF5
-Imbed-os/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832
-Imbed-os/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/TARGET_NRF52_DK
-Imbed-os/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/device
-Imbed-os/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_SDK11/device
-Imbed-os/tools
This isn't a complete list at all, but I'd almost rather just hit compiler errors at this state and work with those rather than continue hunting for header files.
You can get an exhaustive list of flags by generating the Makefile of your project with :
mbed export -i make_gcc_arm -m K64F --profile mbed-os/tools/profiles/debug.json
cf: https://os.mbed.com/docs/v5.6/tools/debugging.html