I am having a hard time figuring out how to add getopt.h in my AIX 7.1. I am using the getopt_long function in my code, which I know is in getopt.h instead of unistd.h (which contains getopt()).
This code is not compiling in AIX:
fatal error: getopt.h: No such file or directory
#include <getopt.h>
^
compilation terminated.
Here are the gcc packages installed:
gcc-4.8.3-1.aix7.1.ppc.rpm
gcc-c++-4.8.3-1.aix7.1.ppc.rpm
libgcc-4.8.3-1.aix7.1.ppc.rpm
gcc-cpp-4.8.3-1.aix7.1.ppc.rpm
I have gone through these links, but they haven't helped much:
http://www.ibm.com/developerworks/aix/library/au-unix-getopt.html#sthash.Loz3H0AH.dpuf
http://www.linuxmisc.com/8-freebsd/eb9bdab1cf6044d5.htm
Also a lot of other web searches.
Am I missing some rpms, or some environment variables?
getopt_long is GNU-only, but you can take free implementation (for example, this claims that it is of BSD license, if I understand it right) or write your own implementation (it's not so hard) and use it in your code.
Related
I recently installed include-what-you-use (IWYU) to try it out. I am on version include-what-you-use 0.12 based on clang version 9.0.1-10. (My OS is Ubuntu 20.04 on WSL1)
I tried to do a very simple example on a source code file, but it quickly comes back as an error on the very first include? (Which is just a c standard library file)
After running
include-what-you-use myutils.cpp:
In file included from myutils.cpp:8:
In file included from ./myutils.h:11:
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/cfloat:42:10: fatal error: 'float.h' file not found
#include <float.h>
^~~~~~~~~
Why is it error'ing out on a c standard library include?
I cannot post the entire source here, and without extensive testing I am not sure what minimal example would cause this problem.
Am I just mis-using IWYU? I installed it via apt rather than building it and llvm/clang/etc from scratch. Is that fine?
I am running Kali-Linux (debian+gnome). When I compile I get compilation error:
cc -Wall -g -c -o frag.o frag.c
frag.c:7:10: fatal error: stropts.h: No such file or directory
7 | #include <stropts.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: frag.o] Error 1
Can anyone tell me what am I missing and what should I install?
I tried installing glibc-sources but still it didn't work out.
As mentioned by the other answer, this library is not used on Linux. Since this came up when trying to compile an application on Linux, it's possible an #if was not set correctly.
As a workaround, look at the source code to see what the #if surrounding the #include is, and set that to false when compiling.
For example, if the code looked like:
#if HAVE_STROPTS_H
#include <stropts.h>
#endif
And if you are using cmake or gcc, run them with -DHAVE_STROPTS_H=0.
stropts.h is part of the Posix STREAMS extension, which Linux never supported. (Since 2008, it has also been marked as obsolescent by Posix, so it may be removed in some future standard revision.)
There have been third-party implementations of STREAMS for Linux, but I don't kniw if any of them are still supported. One which is used by Linux-based telephony apps is contained in openss7.
Another reason not yet mentioned might be the confusion manual introduces. If you need to use ioctl() call, the quickest way to find out the header to include might be pulling up a man ioctl. Well, it turns out there are 2 different manual pages for ioctl(), and having both on the system will result in this misleading and wrong suggestion (accessible directly as man 3 ioctl) of including the stropts.h.
More likely you actually need a sys/ioctl.h, described in man 2 ioctl:
#include <sys/ioctl.h>
Whenever I try to compile this code it always ends up with this error:
In file included from /usr/include/wchar.h:6:0,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/cwchar:44,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iosfwd:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ios:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iostream:39,
from test.cpp:1:
/usr/include/sys/reent.h:14:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
The code I was trying to compile is:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World! :D";
return 0;
}
The error is because your gcc-core package and gcc-g++ are not of the same version. Either downgrade one of them to solve the problem or update both the libraries. Updating both the libraries is the recommended way.
I had this error on a fresh MinGW install, it had nothing to do with the installed packages mentioned in the current accepted answer by "Prasanth Karri". In my case the issue was caused by -nostdinc in my Makefile. I actually only needed that compiler flag when building for a different target platform (not when using MinGW) so I fixed the issue by removing that flag from MinGW builds.
When I was incorporating a software library written in C into an existing demo project(used a C++ mbed library) I encountered this problem. The demo project would compile just fine, but after I replaced the existing main file by my own, this error occurred.
At this point I hadn't yet thought about the fact that the mbed library that I needed was written in C++. My own main file was a .c file that #include the mbed header file. As a result I used my normal C source as if it was a C++ source. Therefore the compiler that was used to compile my main file was the C compiler.
This C compiler then encountered a #include of a module that actually does not exist (within its scope), as it's not a C++ compiler.
Only after I inspected the output of the build log I realised the various source C and C++ files were compiled by more that 1 compiler(the c++ compiler). The project used used compilers arm-none-eabi-c++ and arm-none-eabi-gcc (for embedded systems) as seen below.
Compile log:
Building file: ../anyfile.cpp
Invoking: MCU C++ Compiler
arm-none-eabi-c++ <A lot of arguments> "../anyfile.cpp"
Finished building: ../anyfile.cpp
Building file: ../main.c
Invoking: MCU C Compiler
arm-none-eabi-gcc <A lot of arguments> "../main.c"
In file included from <Project directory>\mbed/mbed.h:21:0,
from ../main.c:16:
<Project directory>\mbed/platform.h:25:19: fatal error: cstddef: No such file or directory
compilation terminated.
Of course in a C++ environment cstddef exists, but in a C environment cstddef doesn't exist, in stead it's just C's implementation of stddef.
In other words, cstddef does not exist in the C compiler.
I resolved this problem by renaming my main.c file to main.cpp and the rest of the code compiled smoothly too.
TLDR/Conclusion: When building a C++ project, avoid mixing C files with C++ files(sources and headers). If possible rename .c files to .cpp files to use the C++ compiler in stead of the C compiler where required.
In order to update it, follow below.
If you are on Windows, just run these on command prompt or powershell
Update the package list: mingw-get update
After updating the package list, run: mingw-get upgrade
Source: How to update GCC in MinGW on Windows?
This problem was solved for me as I installed codeblocks with mingw compiler then I copied the mingw folder from codeblocks to C drive and added
C\mingw\bin to the environment variables.
If you try to compile and see a message like, "fatal error: stddef.h: No such file or directory", the error is because your gcc-core and gcc-g++ packages are not of the same version. Rerun the Cygwin install and make sure that you select the highest numbered versions of gcc-core and gcc-g++.
After installing the C++ compiler with MinGW I encountered this problem as well. Apparently, you have to also install mingw32-base. Go to C:/MinGW/bin/mingw-get.exe (my path) and check it for installation at the Basic Setup tab.
I am running 64bit Linux and using Netbeans 8.0 IDE. I simply created new C++ project, so far only containing some HelloWorld code. I want to use a third party library for logging. I chose log4cpp (since I have experience with Java and it is supposed to have similar interface).
I installed liblog4cpp from the repositories, and can see it in /usr/lib, to be clear:
$ locate log4cpp
/usr/lib/liblog4cpp.so
/usr/lib/liblog4cpp.so.5
/usr/lib/liblog4cpp.so.5.0.5
/usr/lib/x86_64-linux-gnu/liblog4cpp.so
/usr/lib/x86_64-linux-gnu/liblog4cpp.so.5
/usr/share/doc/liblog4cpp5
/usr/share/doc/liblog4cpp5/AUTHORS
/usr/share/doc/liblog4cpp5/NEWS.gz
/usr/share/doc/liblog4cpp5/README
/usr/share/doc/liblog4cpp5/THANKS
/usr/share/doc/liblog4cpp5/TODO
/usr/share/doc/liblog4cpp5/changelog.Debian.gz
/usr/share/doc/liblog4cpp5/changelog.gz
/usr/share/doc/liblog4cpp5/copyright
/var/cache/apt/archives/liblog4cpp5_1.0-4_amd64.deb
/var/lib/dpkg/info/liblog4cpp5.list
/var/lib/dpkg/info/liblog4cpp5.md5sums
/var/lib/dpkg/info/liblog4cpp5.postinst
/var/lib/dpkg/info/liblog4cpp5.postrm
/var/lib/dpkg/info/liblog4cpp5.shlibs
I am having big trouble on how to #include it in my application. Inspired by example from the documentation I put in my source:
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Priority.hh"
I was first using Makefile generated by netbeans, however could not figure out how to configure the project to make it work. All my trials lead to the following error (line 16 being the first #include):
$ make
src/main.cpp:16:31: fatal error: log4cpp/Category.hh: No such file or directory
compilation terminated.
make: *** [build/NetworkConfiguration.o] Error 1
I also tried a custom Makefile, giving g++ argument -llog4cpp, but I always get the same error. I can provide more info/code if it will be helpful. The solution does not need to depend on the IDE, I feel like I just misunderstood how linking works, so feel free to educate me on how to achieve what I want from console with custom Makefile for example.
Since cup still has not posted an answer, I am paraphrasing his comment as an accepted answer.
Install liblog4cpp-dev. The difference is that liblog4cpp only contains the libraries while liblog4cpp-dev is the development kit which includes the headers.
The actual error is a linker error. Undefined reference to get_driver_instance.
Any ideas what the problem is?
This is what I did to install.
Download and install MinGW to C:\MinGW. http://www.mingw.org/
Download boost and move the boost folder to C:\MinGW\include
Download Connector/C++ 1.1.3 http://dev.mysql.com/downloads/connector/cpp/
Move the mysql_connector/include/*.h (recursively) to C:\MinGW\include\
Move the mysql_connector/lib/mysqlcppconn-static.lib to C:\MinGW\lib\libmysqlcppconn-static.a
Move the mysql_connector/lib/mysqlconncpp.dll to C:\MinGW\lib\mysqlconncpp.dll
Alter cppconn/config.h to remove dupication
Copy the C++ example and name it test.cpp http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html
add "using namespace sql::mysql" to the file (as recommended)
run "g++ test.cpp -L C:\MinGW\lib -l mysqlcppconn-static"
It's likely in a namespace.
throw in this and see what happens:
using namespace sql::mysql;
edit: Also, did you look through the approximately 869 other times people have asked this same question on stack overflow before posting?
https://www.google.com/search?q=mysql+get_driver_instance+site:stackoverflow.com
If that isn't it, it can be a problem with c++ name mangling.
https://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B
Because the name-mangling systems for such features are not standardized across compilers, few linkers can link object code that was produced by different compilers.
and I think the final answer is here:
http://www.mingw.org/wiki/MixingCompilers
another stack overflow answer saying this:
What problems can appear when using G++ compiled DLL (plugin) in VC++ compiled application?
You'll need to build the connector from source using your g++ compiler:
http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-installation-source.html