CppUTest error with -std=c++11 on g++ 4.7.2 - c++11

I've been using CppUTest with g++ 4.7.2 for a while now without problems. However, I've just flipped the -std=c++11 option on so I can start using std::unique_ptr and it fails immediately.
Even just compiling the main module:
#include <CppUTest/CommandLineTestRunner.h>
int main(int argc, char ** argv) {
return CommandLineTestRunner::RunAllTests(argc, argv);
}
fails with variations on:
In file included from /usr/include/CppUTest/TestHarness.h:77:0,
from /usr/include/CppUTest/CommandLineTestRunner.h:31,
from tests/testmain.cpp:15:
/usr/include/CppUTest/MemoryLeakWarningPlugin.h:56:53: error: declaration of ‘void* operator new(size_t) throw (std::bad_alloc)’ has a different exception specifier
In file included from /usr/include/c++/4.7/ext/new_allocator.h:34:0,
from /usr/include/c++/4.7/x86_64-linux-gnu/bits/c++allocator.h:34,
from /usr/include/c++/4.7/bits/allocator.h:48,
from /usr/include/c++/4.7/string:43,
from /usr/include/CppUTest/SimpleString.h:136,
from /usr/include/CppUTest/Utest.h:34,
from /usr/include/CppUTest/TestHarness.h:71,
from /usr/include/CppUTest/CommandLineTestRunner.h:31,
from tests/testmain.cpp:15:
/usr/include/c++/4.7/new:93:7: error: from previous declaration ‘void* operator new(std::size_t)’
Removing the -std=c++11 option makes everything work just fine again.
The CppUTest documentation makes some comments about the macros conflicting with overloaded new operators, and suggests #including the standard headers first, but I get this problem without including any headers at all, although it looks like CppUTest/CommandLineTestRunner.h is including <string> itself.
Anyone come across this before or know what the issue is?

Related

Include error when trying to include <wuapi.h>

Recently I tried to create tool using Windows Update Agent API in C++.
The problem is, even include of the wuapi.h header file causes problems on my machine.
It keeps saying, the header file could not be found.
#include <wuapi.h>
int main(int argc, char **args)
{
return 0;
}
Attempt to compile the simple code ends up predictably:
gcc -o tool.exe file.cpp -pedantic -Wall -Wextra
file.cpp:1:10: fatal error: wuapi.h: No such file or directory
#include <wuapi.h>
^~~~~~~~~
compilation terminated.
I found almost no information related to this issue on the Internet so far. That means I'm not sure what's wrong at all.
I'm using Windows 10.0.18362.592 but more importantly I'm using mingw-w64 8.1.0 as a compiler.
At this point I'm not sure, whether mingw-w64 supports this part of Win32 API. I found no useful information though.

CMU pocketsphinx on Mac: GCC throwing errors in stdio.h

I have installed the latest version of both sphinxbase and pocketsphinx on my mac. In this CMU's site
they have provided a simple hello world code to test the validity of the installation. The code looks like:
#include <pocketsphinx.h>
int main(int argc, char *argv[])
{
ps_decoder_t *ps = NULL;
cmd_ln_t *config = NULL;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.bin",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);
return 0;
}
and I have to enter this command below to compile using GCC
gcc -o hello_ps hello_ps.c \
-DMODELDIR=\"`pkg-config --variable=modeldir pocketsphinx`\" \
`pkg-config --cflags --libs pocketsphinx sphinxbase`
where pkg-config would take care about include and library paths.
But the compilation returns the following errors in the stdio.h file (pocketsphinx.h includes the stdio.h).
Restrict requires a pointer or reference (int is invalid)
in several places and also
Unknown typename _FILE (Expanded from macro 'FILE')
I went through stdio.h file and found these corresponding statements and I have no clue what it does. I understand that restrict keyword is not a part of C++ standard but even when compiling with c99, it still throws the same error. Any help would be highly appreciated.
According to the log you have an extra file /usr/local/include/stdio.h which is not a standard include file. This file was installed by some other software and causes problems.
You need to remove problematic stdio.h (and probably other extra headers) from your system.
Correct stdio.h is in /usr/include folder.

Getting Started with C development and GTK+

I'm really a Python developer exclusively, but I'm making my first foray into C programming now, and I'm having a lot of trouble getting started. I can't seem to get the hang of compilation and including libraries. At this point, I'm just identifying the libraries that I need and trying to compile them with a basic "hello, world" app just to make sure that I have my environment setup to do the actual programming.
This is a DBus backend application that will use GIO to connect to DBus.
#include <stdlib.h>
#include <gio/gio.h>
int
main (int argc, char *argv[])
{
printf("hello, world");
return 0;
}
Then, I try to compile:
~$ gcc main.c
main.c:2:21: fatal error: gio/gio.h: No such file or directory
#include <gio/gio.h>
I believe that I've installed the correct packages as indicated here, and gio.h exists at /usr/include/glib-2.0/gio/gio.h.
I found a command online to add a search directory to gcc, but that resulted in other errors:
~$ gcc -I /usr/include/glib-2.0/ main.c
In file included from /usr/include/glib-2.0/glib/galloca.h:34:0,
from /usr/include/glib-2.0/glib.h:32,
from /usr/include/glib-2.0/gobject/gbinding.h:30,
from /usr/include/glib-2.0/glib-object.h:25,
from /usr/include/glib-2.0/gio/gioenums.h:30,
from /usr/include/glib-2.0/gio/giotypes.h:30,
from /usr/include/glib-2.0/gio/gio.h:28,
from main.c:2:
/usr/include/glib-2.0/glib/gtypes.h:34:24: fatal error: glibconfig.h: No such file or directory
#include <glibconfig.h>
^
compilation terminated.
There has to be some relatively simple method for being able to set some options/variables (makefile?) to automatically include the necessary headers. I'm also going to use Eclipse-CDT or Anjuta as an IDE and would appreciate help to fix the import path (or whatever it's called in C).
Any help is greatly appreciated.
Use pkg-config (and make). See exactly this answer to a very similar question. See also this and that answers. Don't forget -Wall -g flags to gcc ..
You don't need an IDE to compile your code (the IDE will just run some gcc commands, so better know how to use them yourself).

gnu cgi (cgicc) does not compile with gcc on Windows using MinGW/Cygwin

I have to build a "proof of concept" using cgicc on Windows. But currently I am unable to build cgicc. The current release of cgicc v3.2.9 won't build neither in MinGW (gcc v4.5.0 / v3.4.5) nor Cygwin (gcc v4.3.4-3).
By using gcc v3.4.5 and automake in MinGW I got:
HTMLAttributeList.cpp:51: internal compiler error: in rest_of_handle_final, at toplev.c:2067
Please submit a full bug report, with preprocessed source if appropriate.
Using gcc v4.3.4 and automake gives for Cygwin:
In file included from CgiEnvironment.cpp:36:
../cgicc/CgiEnvironment.h:52: error: explicit instantiation of 'class std::vector<cgicc::HTTPCookie, std::allocator<cgicc::HTTPCookie> >' in namespace 'cgicc'
which does not enclose namespace 'std')
and for gcc v4.5.0 in MinGW:
../cgicc/CgiEnvironment.h:52:33: error: explicit instantiation of 'class std::vector<cgicc::HTTPCookie>' in namespace 'cgicc' (which does not enclose namespace
'std')
I tried to ignore the Automake and Autoconf scripts. I set up Eclipse-CDT for using the apropriate compiler switches (I also tried Code::Blocks):
-DHAVE_CONFIG_H -DWIN32 -I.. -Wall -W -pedantic -g -DDLL_EXPORT -DPIC -DCGICC_EXPORTS
But again I got:
explicit instantiation of 'class std::vector<cgicc::HTTPCookie, std::allocator<cgicc::HTTPCookie> >' in namespace 'cgicc' (which does not enclose namespace 'std') CgiEnvironment.h /cgicc/cgicc line 52
CgiEnvironment.h:51 to line 53 contains the ifdef WIN32:
#include <string>
#include <vector>
#include <cstdlib>
namespace cgicc {
...
#ifdef WIN32
template class CGICC_API std::vector<HTTPCookie>;
#endif
...
}
What goes wrong? Any suggestions?
Now I can compile cgicc. Thanks to a very good friend of mine, Vlad Lazarenko and some hours of investigation. But I have to do some major changes.
My friend helped me to go on the right way by understanding the main issue. He and Vlad Lazarenko gave me a good direction to investigate the __declspec(). This is a feature of Microsoft compilers which are now supported in gcc.
During investigation I stumbled over a post with migration hints for GCC3.4.3 to GCC4.1.2. So I moved the explicit instantiation of the templates behind the declared namespace in following headers:
Cgicc.h
CgiEnvironment.h
HTMLAttributeList.h
HTMLElementList.h
Next I discovered a strange behaviour while checking different compiler switches and other things regarding my build environment. During investigatiopn of cgicc header files the defined -DCGICC_EXPORTS becomes sometimes undefined (expansion is shown by Eclipse CDT). So I changed CgiDefs.h from:
// export library symbols
#ifdef CGICC_EXPORTS
# define CGICC_API __declspec(dllexport)
#else
# define CGICC_API __declspec(dllimport)
#endif
to
# define CGICC_API __declspec(dllimport)
At the end I changed the compiler switches to
-DWIN32 -DCGICC_EXPORTS -DHAVE_CONFIG_H -I.. -O0 -g3 -Wall -c -fmessage-length=0 -std=gnu++98. Most important is -std=gnu++98. Without gnu extensions __declspec() wont generate any symbols - even for a static library. I do not understand why I need that for a static library because the symbols should be in their object files which are packet into libcgicc.a.
Now some further questions:
Do anyone know a mechanism how CGICC_EXPORTS can became undefined
without #undef CGICC_EXPORTS and without -UCGICC_EXPORTS?
Why I have to use gnu extensions? I thought the defaults are independend.
Why do I have to use __declspec(dllexport) for a static library?
Why it is not enough to use the object files of a static library? Let me ask the same
in a different way: Why are no symbols found if I try to link object files of a static
library?
What is the advantage/disadvantage of "implicit template instantiation and vague
linkage" versus "explicit template instantiation"?
The CGICC_API should be either defined as __declspec(dllimport) or __declspec(dllexport).
It looks like that DLL_EXPORT macro that gets defined in command line should affect that, but it doesn't.
My guess is that some header handling it is not included. See this and that for more information.

undefined reference to `SDL_main'

I am trying to build a project on windows using MinGW and eclipse.
I'm using the SDL library but when i try to complie it, I get the error
g++ -Wl,-subsystem,windows -oplikoo.exe src\mouse.o src\camera.o src\Timer.o src\Pegs.o src\Graphics.o src\FPS.o src\Ball.o -lmingw32 -lSDLmain -lSDL.dll -lSDL_image -lSDL_mixer
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../libSDLmain.a(SDL_win32_main.o): In function `console_main':
/Users/hercules/trunk/SDL-1.2/./src/main/win32/SDL_win32_main.c:315: undefined reference to `SDL_main'
I understand that main has to have the int main(int argc, char *argv[]) signature, and #include <SDL.h> in that file, but it still does not work.
This just happend to me. When i started to define main with the args parameters:
int main(int argc, char* args[])
the compiler error wen away.
main.cpp was not in src dir, not being compiled
Scanning over your compilation line there, I noticed you are attempting to link against "SDL.dll" directly. That's not what you want. You should be linking against libSDL.la (provided you are actually using mingw).
Also, I'm not sure if this affects anything here, but I've heard that you are "supposed to" link to "SDL" last.

Resources