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

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.

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.

How do you compile C++ programs that include LLVM API headers?

I'm trying to use the C++ compiler to compile the following program:
#include <stdio.h>
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/IR/Module.h"
int main( int argc, char* argv[] )
{
if( argc < 2 )
llvm::errs() << "Expected an argument - IR file name\n";
llvm::LLVMContext &context = llvm::getGlobalContext();
llvm::SMDiagnostic err;
llvm::Module* module = llvm::ParseIRFile( argv[1], err, context );
if( !mod )
{
err.print( argv[0], errs() );
return 1;
}
return 0;
}
I'm trying to compile the program using the following command:
clang++ main.cpp -o main
However, when I compile, I'm getting the following compile error:
main.cpp:2:10: fatal error: 'llvm/IR/LLVMContext.h' file not found
#include "llvm/IR/LLVMContext.h"
^
1 error generated.
In this case, I'm not exactly sure how to link the LLVM API headers when compiling main.cpp with Clang.
Any help would be greatly appreciated.
You can use the following command:
g++ -std=c++11 main.cpp `llvm-config --system-libs --cppflags --ldflags --libs core` -o main
Where --libs and --system-libs flags are used for linking and --cppflags takes care of include paths.
Thank You
You need LLVM checked out or installed somewhere on your system. You can download a binary release (with headers and libraries you can build against) as explained here: http://llvm.org/releases/download.html#3.5
You can also check out LLVM from its SVN repository as explained here: http://llvm.org/docs/GettingStarted.html#checkout
Once you do that, I recommend looking at the llvm-clang-samples repository that comes with a Makefiles showing how to build sample programs vs. an up-to-date LLVM.

toquelib behaves different with static and dynamic linking

This is puzzling me...
I have a code that looks like this:
#include <stdio.h>
#include <pbs_ifl.h>
int doSomeStuff()
{
char *server_name;
int c;
server_name = pbs_default();
c = pbs_connect(server_name);
printf("pbs_errno %d\n",pbs_errno);
// do some stuff
pbs_disconnect(c);
}
When I compile it with:
gcc -static -o executablename sourcefile.c -ltorque
It works allright, compiling with '-static'. pbs_errno is 0 and I can do my stuff.
But if I remove the '-static' flag it starts giving me this message when I run it:
munge: Error: Unable to access "/var/run/munge/munge.socket.2": No such file or directory
So... I start the munge service (munged) and it stops complaining about it, but instead I get pbs_errno=15033 and can't get anything from the cluster (do my stuff).
Any ideas?
I don't know if I delete de question or answer it, but it seems so be solved... so I'm posting the solution here.
I had 2 versions of the lib installed, one via yum other via source.
Since only the compiled code had the static libs, when I was linking -static gcc was linking with the compiled code and when I was linking dynamic it was linking with the yum version.
I just had to enforce the linking with the right libs adding the following flag when liking:
-Wl,-rpath=/usr/local/lib

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).

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

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?

Resources