Why does my Thrift (c_glib) example fail to compile with "error: invalid conversion"? - c

I'm trying out the thrift c_glib example (minimal version just with ping) that is available in the official thrift website, but whenever i compile the code (gcc or make) it fails with following reason:
thrift-server.c: In function ‘int main()’:
thrift-server.c:186:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘TutorialCalculatorHandler* {aka _TutorialCalculatorHandler*}’ [-fpermissive]
NULL);
^
thrift-server.c:194:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘CalculatorProcessor* {aka _CalculatorProcessor*}’ [-fpermissive]
NULL);
^
thrift-server.c:201:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftServerTransport* {aka _ThriftServerTransport*}’ [-fpermissive]
NULL);
^
thrift-server.c:208:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftTransportFactory* {aka _ThriftTransportFactory*}’ [-fpermissive]
NULL);
^
thrift-server.c:214:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftProtocolFactory* {aka _ThriftProtocolFactory*}’ [-fpermissive]
NULL);
^
thrift-server.c:225:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftServer* {aka _ThriftServer*}’ [-fpermissive]
NULL);
^
thrift-server.c:176:7: warning: unused variable ‘exit_status’ [-Wunused-variable]
int exit_status = 0;
^
thrift-server.c: At global scope:
thrift-server.c:154:1: warning: ‘void sigint_handler(int)’ defined but not used [-Wunused-function]
sigint_handler (int signal_number)
^
make: *** [server] Error 1
Any pointers will be really helpful. My GCC version is 4.8.2 and I'm on a ubuntu 14.10 box
And my makefile looks like this:
default: server
server: thrift-server.c
gcc -g -Wall -Wextra -pedantic -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -g -O2 -o thrift-server.o -c thrift-server.c /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/tutorial/c_glib/.libs/libtutorialgencglib.a -lgobject-2.0 -lglib-2.0 /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs/libthrift_c_glib.so /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs/libthrift_c_glib.so -lssl -lcrypto -lrt -lpthread -Wl,-rpath -Wl,/home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs
This is how my .thrift file looks like:
namespace cpp tutorial
service Calculator {
void ping()
}
And this is the thrift-server.c:
http://pastebin.com/Q4SGAdMu

Try compiling your code with gcc, not g++ (change the last line of your makefile). C++, but not C, requires explicit conversions from void *.
If you must use g++ for some reason, try instead adding an explicit cast to each call to g_object_new, e.g.:
handler = (TutorialCalculatorHandler *)
g_object_new (TYPE_TUTORIAL_CALCULATOR_HANDLER,
NULL);

Related

Error trying to build aws-c-common package using CMake

Hi I was trying to install and build the aws-c-common package provided by AWS.
However I encountered below errors when I'm trying to execute below command:
cmake --build . && cmake --build . --target install && cd ..
Which is the command that I'm following from AWS Documentation Option B.
The error are shown as below (The error logs are very long and I can only pasted a portion of it here. But basically I can see error with each different file with different error reason, but I'm not sure why is it happening since I followed all the previous steps in the guide)
[1/58] Building C object CMakeFiles/aws-c-common.dir/source/log_formatter.c.obj
FAILED: CMakeFiles/aws-c-common.dir/source/log_formatter.c.obj
C:\MinGW\bin\gcc.exe -DAWS_AFFINITY_METHOD=AWS_AFFINITY_METHOD_NONE -DAWS_COMMON_EXPORTS -DAWS_COMMON_USE_IMPORT_EXPORT -DHAVE_AVX2_INTRINSICS -DUSE_SIMD_ENCODING -DWINDOWS_KERNEL_LIB=Kernel32 -
Daws_c_common_EXPORTS -Ibuild/aws-c-common/include -Igenerated/include -O3 -DNDEBUG -Wall -Wstrict-prototypes -fno-omit-frame-pointer -pedantic -Wno-long-long -fPIC -fvisibility=hidden -std=gnu9
9 -MD -MT CMakeFiles/aws-c-common.dir/source/log_formatter.c.obj -MF CMakeFiles\aws-c-common.dir\source\log_formatter.c.obj.d -o CMakeFiles/aws-c-common.dir/source/log_formatter.c.obj -c build/a
ws-c-common/source/log_formatter.c
In file included from build/aws-c-common/include/aws/common/array_list.h:210:0,
from build/aws-c-common/include/aws/common/byte_buf.h:8,
from build/aws-c-common/include/aws/common/string.h:7,
from build/aws-c-common/source/log_formatter.c:9:
build/aws-c-common/include/aws/common/array_list.inl: In function 'aws_array_list_debug_print':
build/aws-c-common/include/aws/common/array_list.inl:99:48: warning: unknown conversion type character 'z' in format [-Wformat=]
"arraylist %p. Alloc %p. current_size %zu. length %zu. item_size %zu. data %p\n",
^
build/aws-c-common/include/aws/common/array_list.inl:99:60: warning: unknown conversion type character 'z' in format [-Wformat=]
"arraylist %p. Alloc %p. current_size %zu. length %zu. item_size %zu. data %p\n",
^
build/aws-c-common/include/aws/common/array_list.inl:99:75: warning: unknown conversion type character 'z' in format [-Wformat=]
"arraylist %p. Alloc %p. current_size %zu. length %zu. item_size %zu. data %p\n",
^
build/aws-c-common/include/aws/common/array_list.inl:99:85: warning: format '%p' expects argument of type 'void *', but argument 4 has type 'size_t {aka const unsigned int}' [-Wformat=]
"arraylist %p. Alloc %p. current_size %zu. length %zu. item_size %zu. data %p\n",
^
build/aws-c-common/include/aws/common/array_list.inl:99:9: warning: too many arguments for format [-Wformat-extra-args]
"arraylist %p. Alloc %p. current_size %zu. length %zu. item_size %zu. data %p\n",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from build/aws-c-common/include/aws/common/byte_order.h:69:0,
from build/aws-c-common/include/aws/common/byte_buf.h:9,
from build/aws-c-common/include/aws/common/string.h:7,
from build/aws-c-common/source/log_formatter.c:9:
build/aws-c-common/include/aws/common/byte_order.inl: In function 'aws_hton64':
build/aws-c-common/include/aws/common/byte_order.inl:47:23: warning: implicit declaration of function 'htonl' [-Wimplicit-function-declaration]
return ((uint64_t)htonl(low)) << 32 | htonl(high);
^~~~~
build/aws-c-common/include/aws/common/byte_order.inl: In function 'aws_hton32':
build/aws-c-common/include/aws/common/byte_order.inl:63:38: warning: implicit declaration of function '_byteswap_ulong' [-Wimplicit-function-declaration]
return aws_is_big_endian() ? x : _byteswap_ulong(x);
^~~~~~~~~~~~~~~
build/aws-c-common/include/aws/common/byte_order.inl: In function 'aws_hton16':
build/aws-c-common/include/aws/common/byte_order.inl:145:38: warning: implicit declaration of function '_byteswap_ushort' [-Wimplicit-function-declaration]
return aws_is_big_endian() ? x : _byteswap_ushort(x);
^~~~~~~~~~~~~~~~
build/aws-c-common/source/log_formatter.c: In function 'aws_format_standard_log_line':
build/aws-c-common/source/log_formatter.c:155:29: warning: implicit declaration of function 'vsnprintf_s' [-Wimplicit-function-declaration]
int written_count = vsnprintf_s(
^~~~~~~~~~~
build/aws-c-common/source/log_formatter.c:158:13: error: '_TRUNCATE' undeclared (first use in this function)
_TRUNCATE,
^~~~~~~~~
build/aws-c-common/source/log_formatter.c:158:13: note: each undeclared identifier is reported only once for each function it appears in
[2/58] Building C object CMakeFiles/aws-c-common.dir/source/windows/rw_lock.c.obj
FAILED: CMakeFiles/aws-c-common.dir/source/windows/rw_lock.c.obj
C:\MinGW\bin\gcc.exe -DAWS_AFFINITY_METHOD=AWS_AFFINITY_METHOD_NONE -DAWS_COMMON_EXPORTS -DAWS_COMMON_USE_IMPORT_EXPORT -DHAVE_AVX2_INTRINSICS -DUSE_SIMD_ENCODING -DWINDOWS_KERNEL_LIB=Kernel32 -
Daws_c_common_EXPORTS -Ibuild/aws-c-common/include -Igenerated/include -O3 -DNDEBUG -Wall -Wstrict-prototypes -fno-omit-frame-pointer -pedantic -Wno-long-long -fPIC -fvisibility=hidden -std=gnu9
9 -MD -MT CMakeFiles/aws-c-common.dir/source/windows/rw_lock.c.obj -MF CMakeFiles\aws-c-common.dir\source\windows\rw_lock.c.obj.d -o CMakeFiles/aws-c-common.dir/source/windows/rw_lock.c.obj -c b
uild/aws-c-common/source/windows/rw_lock.c
build/aws-c-common/source/windows/rw_lock.c:9:22: fatal error: synchapi.h: No such file or directory
#include <synchapi.h>
^
compilation terminated.
[3/58] Building C object CMakeFiles/aws-c-common.dir/source/windows/clock.c.obj
FAILED: CMakeFiles/aws-c-common.dir/source/windows/clock.c.obj
C:\MinGW\bin\gcc.exe -DAWS_AFFINITY_METHOD=AWS_AFFINITY_METHOD_NONE -DAWS_COMMON_EXPORTS -DAWS_COMMON_USE_IMPORT_EXPORT -DHAVE_AVX2_INTRINSICS -DUSE_SIMD_ENCODING -DWINDOWS_KERNEL_LIB=Kernel32 -
Daws_c_common_EXPORTS -Ibuild/aws-c-common/include -Igenerated/include -O3 -DNDEBUG -Wall -Wstrict-prototypes -fno-omit-frame-pointer -pedantic -Wno-long-long -fPIC -fvisibility=hidden -std=gnu9
9 -MD -MT CMakeFiles/aws-c-common.dir/source/windows/clock.c.obj -MF CMakeFiles\aws-c-common.dir\source\windows\clock.c.obj.d -o CMakeFiles/aws-c-common.dir/source/windows/clock.c.obj -c build/a
ws-c-common/source/windows/clock.c
build/aws-c-common/source/windows/clock.c:13:8: error: unknown type name 'INIT_ONCE'
static INIT_ONCE s_timefunc_init_once = INIT_ONCE_STATIC_INIT;
^~~~~~~~~
build/aws-c-common/source/windows/clock.c:13:41: error: 'INIT_ONCE_STATIC_INIT' undeclared here (not in a function)
static INIT_ONCE s_timefunc_init_once = INIT_ONCE_STATIC_INIT;
^~~~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/clock.c:22:50: error: unknown type name 'PINIT_ONCE'
static BOOL CALLBACK s_get_system_time_init_once(PINIT_ONCE init_once, PVOID param, PVOID *context) {
^~~~~~~~~~
build/aws-c-common/source/windows/clock.c: In function 's_get_system_time_func_lazy_init':
build/aws-c-common/source/windows/clock.c:40:19: warning: implicit declaration of function 'InitOnceExecuteOnce' [-Wimplicit-function-declaration]
BOOL status = InitOnceExecuteOnce(&s_timefunc_init_once, s_get_system_time_init_once, NULL, NULL);
^~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/clock.c:40:62: error: 's_get_system_time_init_once' undeclared (first use in this function)
BOOL status = InitOnceExecuteOnce(&s_timefunc_init_once, s_get_system_time_init_once, NULL, NULL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/clock.c:40:62: note: each undeclared identifier is reported only once for each function it appears in
[4/58] Building C object CMakeFiles/aws-c-common.dir/source/windows/condition_variable.c.obj
FAILED: CMakeFiles/aws-c-common.dir/source/windows/condition_variable.c.obj
C:\MinGW\bin\gcc.exe -DAWS_AFFINITY_METHOD=AWS_AFFINITY_METHOD_NONE -DAWS_COMMON_EXPORTS -DAWS_COMMON_USE_IMPORT_EXPORT -DHAVE_AVX2_INTRINSICS -DUSE_SIMD_ENCODING -DWINDOWS_KERNEL_LIB=Kernel32 -
Daws_c_common_EXPORTS -Ibuild/aws-c-common/include -Igenerated/include -O3 -DNDEBUG -Wall -Wstrict-prototypes -fno-omit-frame-pointer -pedantic -Wno-long-long -fPIC -fvisibility=hidden -std=gnu9
9 -MD -MT CMakeFiles/aws-c-common.dir/source/windows/condition_variable.c.obj -MF CMakeFiles\aws-c-common.dir\source\windows\condition_variable.c.obj.d -o CMakeFiles/aws-c-common.dir/source/wind
ows/condition_variable.c.obj -c build/aws-c-common/source/windows/condition_variable.c
In file included from build/aws-c-common/include/aws/common/allocator.h:8:0,
from build/aws-c-common/include/aws/common/common.h:12,
from build/aws-c-common/include/aws/common/condition_variable.h:9,
from build/aws-c-common/source/windows/condition_variable.c:6:
build/aws-c-common/source/windows/condition_variable.c: In function 'aws_condition_variable_init':
build/aws-c-common/source/windows/condition_variable.c:17:30: error: 'CONDITION_VARIABLE' undeclared (first use in this function)
AWS_STATIC_ASSERT(sizeof(CONDITION_VARIABLE) == sizeof(condition_variable->condition_handle));
^
build/aws-c-common/include/aws/common/macros.h:18:40: note: in expansion of macro 'AWS_STATIC_ASSERT0'
#define AWS_STATIC_ASSERT1(cond, line) AWS_STATIC_ASSERT0(cond, AWS_CONCAT(at_line_, line))
^~~~~~~~~~~~~~~~~~
build/aws-c-common/include/aws/common/macros.h:19:33: note: in expansion of macro 'AWS_STATIC_ASSERT1'
#define AWS_STATIC_ASSERT(cond) AWS_STATIC_ASSERT1(cond, __LINE__)
^~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:17:5: note: in expansion of macro 'AWS_STATIC_ASSERT'
AWS_STATIC_ASSERT(sizeof(CONDITION_VARIABLE) == sizeof(condition_variable->condition_handle));
^~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:17:30: note: each undeclared identifier is reported only once for each function it appears in
AWS_STATIC_ASSERT(sizeof(CONDITION_VARIABLE) == sizeof(condition_variable->condition_handle));
^
build/aws-c-common/include/aws/common/macros.h:18:40: note: in expansion of macro 'AWS_STATIC_ASSERT0'
#define AWS_STATIC_ASSERT1(cond, line) AWS_STATIC_ASSERT0(cond, AWS_CONCAT(at_line_, line))
^~~~~~~~~~~~~~~~~~
build/aws-c-common/include/aws/common/macros.h:19:33: note: in expansion of macro 'AWS_STATIC_ASSERT1'
#define AWS_STATIC_ASSERT(cond) AWS_STATIC_ASSERT1(cond, __LINE__)
^~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:17:5: note: in expansion of macro 'AWS_STATIC_ASSERT'
AWS_STATIC_ASSERT(sizeof(CONDITION_VARIABLE) == sizeof(condition_variable->condition_handle));
^~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:20:5: warning: implicit declaration of function 'InitializeConditionVariable' [-Wimplicit-function-declaration]
InitializeConditionVariable(AWSCV_TO_WINDOWS(condition_variable));
^~~~~~~~~~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:13:32: error: 'PCONDITION_VARIABLE' undeclared (first use in this function)
#define AWSCV_TO_WINDOWS(pCV) (PCONDITION_VARIABLE) & (pCV)->condition_handle
^
build/aws-c-common/source/windows/condition_variable.c:20:33: note: in expansion of macro 'AWSCV_TO_WINDOWS'
InitializeConditionVariable(AWSCV_TO_WINDOWS(condition_variable));
^~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c: In function 'aws_condition_variable_notify_one':
build/aws-c-common/source/windows/condition_variable.c:32:5: warning: implicit declaration of function 'WakeConditionVariable' [-Wimplicit-function-declaration]
WakeConditionVariable(AWSCV_TO_WINDOWS(condition_variable));
^~~~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:13:32: error: 'PCONDITION_VARIABLE' undeclared (first use in this function)
#define AWSCV_TO_WINDOWS(pCV) (PCONDITION_VARIABLE) & (pCV)->condition_handle
^
build/aws-c-common/source/windows/condition_variable.c:32:27: note: in expansion of macro 'AWSCV_TO_WINDOWS'
WakeConditionVariable(AWSCV_TO_WINDOWS(condition_variable));
^~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c: In function 'aws_condition_variable_notify_all':
build/aws-c-common/source/windows/condition_variable.c:38:5: warning: implicit declaration of function 'WakeAllConditionVariable' [-Wimplicit-function-declaration]
WakeAllConditionVariable(AWSCV_TO_WINDOWS(condition_variable));
^~~~~~~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:13:32: error: 'PCONDITION_VARIABLE' undeclared (first use in this function)
#define AWSCV_TO_WINDOWS(pCV) (PCONDITION_VARIABLE) & (pCV)->condition_handle
^
build/aws-c-common/source/windows/condition_variable.c:38:30: note: in expansion of macro 'AWSCV_TO_WINDOWS'
WakeAllConditionVariable(AWSCV_TO_WINDOWS(condition_variable));
^~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c: In function 'aws_condition_variable_wait':
build/aws-c-common/source/windows/condition_variable.c:46:9: warning: implicit declaration of function 'SleepConditionVariableSRW' [-Wimplicit-function-declaration]
if (SleepConditionVariableSRW(AWSCV_TO_WINDOWS(condition_variable), AWSMUTEX_TO_WINDOWS(mutex), INFINITE, 0)) {
^~~~~~~~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c:13:32: error: 'PCONDITION_VARIABLE' undeclared (first use in this function)
#define AWSCV_TO_WINDOWS(pCV) (PCONDITION_VARIABLE) & (pCV)->condition_handle
^
build/aws-c-common/source/windows/condition_variable.c:46:35: note: in expansion of macro 'AWSCV_TO_WINDOWS'
if (SleepConditionVariableSRW(AWSCV_TO_WINDOWS(condition_variable), AWSMUTEX_TO_WINDOWS(mutex), INFINITE, 0)) {
^~~~~~~~~~~~~~~~
In file included from build/aws-c-common/source/windows/condition_variable.c:9:0:
build/aws-c-common/include/aws/common/mutex.h:12:42: error: 'PSRWLOCK' undeclared (first use in this function)
# define AWSMUTEX_TO_WINDOWS(pMutex) (PSRWLOCK) & (pMutex)->mutex_handle
^
build/aws-c-common/source/windows/condition_variable.c:46:73: note: in expansion of macro 'AWSMUTEX_TO_WINDOWS'
if (SleepConditionVariableSRW(AWSCV_TO_WINDOWS(condition_variable), AWSMUTEX_TO_WINDOWS(mutex), INFINITE, 0)) {
^~~~~~~~~~~~~~~~~~~
build/aws-c-common/source/windows/condition_variable.c: In function 'aws_condition_variable_wait_for':
build/aws-c-common/source/windows/condition_variable.c:13:32: error: 'PCONDITION_VARIABLE' undeclared (first use in this function)
#define AWSCV_TO_WINDOWS(pCV) (PCONDITION_VARIABLE) & (pCV)->condition_handle
^
build/aws-c-common/source/windows/condition_variable.c:63:35: note: in expansion of macro 'AWSCV_TO_WINDOWS'
if (SleepConditionVariableSRW(AWSCV_TO_WINDOWS(condition_variable), AWSMUTEX_TO_WINDOWS(mutex), time_ms, 0)) {
^~~~~~~~~~~~~~~~
In file included from build/aws-c-common/source/windows/condition_variable.c:9:0:
build/aws-c-common/include/aws/common/mutex.h:12:42: error: 'PSRWLOCK' undeclared (first use in this function)
# define AWSMUTEX_TO_WINDOWS(pMutex) (PSRWLOCK) & (pMutex)->mutex_handle
^
build/aws-c-common/source/windows/condition_variable.c:63:73: note: in expansion of macro 'AWSMUTEX_TO_WINDOWS'
if (SleepConditionVariableSRW(AWSCV_TO_WINDOWS(condition_variable), AWSMUTEX_TO_WINDOWS(mutex), time_ms, 0)) {
^~~~~~~~~~~~~~~~~~~
[5/58] Building C object CMakeFiles/aws-c-common.dir/source/windows/file.c.obj
FAILED: CMakeFiles/aws-c-common.dir/source/windows/file.c.obj
C:\MinGW\bin\gcc.exe -DAWS_AFFINITY_METHOD=AWS_AFFINITY_METHOD_NONE -DAWS_COMMON_EXPORTS -DAWS_COMMON_USE_IMPORT_EXPORT -DHAVE_AVX2_INTRINSICS -DUSE_SIMD_ENCODING -DWINDOWS_KERNEL_LIB=Kernel32 -
Daws_c_common_EXPORTS -Ibuild/aws-c-common/include -Igenerated/include -O3 -DNDEBUG -Wall -Wstrict-prototypes -fno-omit-frame-pointer -pedantic -Wno-long-long -fPIC -fvisibility=hidden -std=gnu9
9 -MD -MT CMakeFiles/aws-c-common.dir/source/windows/file.c.obj -MF CMakeFiles\aws-c-common.dir\source\windows\file.c.obj.d -o CMakeFiles/aws-c-common.dir/source/windows/file.c.obj -c build/aws-
c-common/source/windows/file.c
build/aws-c-common/source/windows/file.c: In function 'aws_fopen':
build/aws-c-common/source/windows/file.c:18:17: error: 'EINVAL' undeclared (first use in this function)
errno = EINVAL;
^~~~~~
build/aws-c-common/source/windows/file.c:18:17: note: each undeclared identifier is reported only once for each function it appears in
build/aws-c-common/source/windows/file.c:27:9: warning: implicit declaration of function '_wfopen_s' [-Wimplicit-function-declaration]
if (_wfopen_s(&file, w_file_path, w_mode)) {
^~~~~~~~~
Does anyone know how to resolve this?
Thank you.

How should I compile this old code with cc

I'm trying to compile source code, that from 2001, in Ubuntu 18.04.2 LTS. But, I got the errors below and actually don't know how I have to change the compiling code. Can you help me for compiling this code?
Suggested compilation part from the program
SUGGESTED COMPILATION COMMAND LINE (FOR A DEC-ALPHA CC-COMPILER):
cc -lm -fast -tune host -arch host -assume whole_program \
-o mol_volume mol_volume.c
When I tried this code, errors;
cc: error: host: No such file or directory
cc: error: host: No such file or directory
cc: error: whole_program: No such file or directory
cc: error: unrecognized command line option ‘-fast’; did you mean ‘-Ofast’?
cc: error: unrecognized command line option ‘-tune’; did you mean ‘-mtune=’?
cc: error: unrecognized command line option ‘-arch’; did you mean ‘-march=’?
cc: error: unrecognized command line option ‘-assume’; did you mean ‘-msse’?
Then, I changed -fast, -tune, -arch, -assume flags with -Ofast, -mtune=native, -march=native, -msse then add the path the for the directory part of the errors.
cc -lm -Ofast -mtune=native -march=native -msse /mypath/ -o mol_volume mol_volume.c
Then, I got that error;
mol_volume.c: In function ‘main’:
mol_volume.c:235:10: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
while( gets(s) ) {
^~~~
fgets
mol_volume.c:311:26: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
printf("WARNING: the %i-th atom of the pdb file %s has an unknown chemical type %s.\n",
~^
%li
i+1, pdb_name, atom_type);
~~~
/usr/bin/ld: cannot find .: File format not recognized
collect2: error: ld returned 1 exit status
You can access the source code via this link;
Source Code
My PC info:
Operation System: Ubuntu 18.04.2 LTS
Kernel ver.: 4.15.0-50-generic
GCC ver.: 7.4.0
gets was removed in C11. Compile with gcc -o mol_volume -Wall -std=c99 -mtune=native -O3 mol_volume.c -lm.
It will work but you should fix the code to remove all the warnings.

mex file generated by Matlab-coder: how to re-compile

I recently got some of my Matlab code converted to C and it works. However, I would like to make some changes to these mex file and recompile.
So far, I have only worked with simple mex project: usually consisting of two files like this:
Matlab_mex_Testing.m <--- I call mex function from here.
mexcallingmatlab.c
then I can compile using:
mex -g -ldl CFLAGS="\$CFLAGS -std=c99" -largeArrayDims mexcallingmatlab.c
However, the converted project has multiple *.c, *.o files and when I tried to compile only the ...._mex.c, I get following error:
ConstructSystemMatrix_2Translate_mex.c:24:1: warning: excess elements in struct initializer [enabled by default]
emlrtContext emlrtContextGlobal = { true, false, EMLRT_VERSION_INFO, NULL, "ConstructSystemMatrix_2Translate", NULL, false, {2045744189U,2170104910U,2743257031U,4284093946U}, 0, false, 1, false };
^
ConstructSystemMatrix_2Translate_mex.c:24:1: warning: (near initialization for ‘emlrtContextGlobal’) [enabled by default]
ConstructSystemMatrix_2Translate_mex.c:24:1: warning: excess elements in struct initializer [enabled by default]
ConstructSystemMatrix_2Translate_mex.c:24:1: warning: (near initialization for ‘emlrtContextGlobal’) [enabled by default]
ConstructSystemMatrix_2Translate_mex.c:24:1: warning: excess elements in struct initializer [enabled by default]
ConstructSystemMatrix_2Translate_mex.c:24:1: warning: (near initialization for ‘emlrtContextGlobal’) [enabled by default]
ConstructSystemMatrix_2Translate_mex.c: In function ‘mexFunction’:
ConstructSystemMatrix_2Translate_mex.c:57:3: warning: implicit declaration of function ‘emlrtClearAllocCount’ [-Wimplicit-function-declaration]
emlrtClearAllocCount(&emlrtContextGlobal, 0, 0, NULL);
^
ConstructSystemMatrix_2Translate_mex.o: In function `ConstructSystemMatrix_2Translate_mexFunction':
/home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:37: undefined reference to `ConstructSystemMatrix_2Translate_initialize'
/home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:39: undefined reference to `ConstructSystemMatrix_2Translate_api'
/home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:41: undefined reference to `ConstructSystemMatrix_2Translate_terminate'
ConstructSystemMatrix_2Translate_mex.o: In function `ConstructSystemMatrix_2Translate_atexit_wrapper':
/home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:50: undefined reference to `ConstructSystemMatrix_2Translate_atexit'
ConstructSystemMatrix_2Translate_mex.o: In function `mexFunction':
/home/dkumar/Desktop/codegen/mex/ConstructSystemMatrix_2Translate/ConstructSystemMatrix_2Translate_mex.c:57: undefined reference to `emlrtClearAllocCount'
collect2: error: ld returned 1 exit status
mex: link of ' "ConstructSystemMatrix_2Translate_mex.mexa64"' failed.
mex -g -ldl CFLAGS="\$CFLAGS -std=c99" -largeArrayDims ConstructSystemMatrix_2Translate_mex.c: Signal 127
ans =
255
I can see that various header files such as "ConstructSystemMatrix_2Translate_initialize.h" etc are properly included.
I also see that there is a *.mki file with following contents:
# Make settings for ConstructSystemMatrix_2Translate
CC=gcc
CFLAGS=-ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CLIBS=-Wl,-rpath-link,/usr/local/MATLAB/R2012a/bin/glnxa64 -L/usr/local/MATLAB/R2012a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
COPTIMFLAGS=-O -DNDEBUG
CDEBUGFLAGS=-g
CXX=g++
CXXFLAGS=-ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXLIBS=-Wl,-rpath-link,/usr/local/MATLAB/R2012a/bin/glnxa64 -L/usr/local/MATLAB/R2012a/bin/glnxa64 -lmx -lmex -lmat -lm
CXXOPTIMFLAGS=-O -DNDEBUG
CXXDEBUGFLAGS=-g
LD=gcc
LDFLAGS=-pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2012a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDOPTIMFLAGS=-O
LDDEBUGFLAGS=-g
Arch=glnxa64
OMPFLAGS=
OMPLINKFLAGS=
EMC_COMPILER=
EMC_CONFIG=optim
Am I supposed to make some makefile out of this? If yes, could someone guide me?
I am running Matlab R2014b (64 bits)

Makefile and program structure Raspberry Pi GCC

I' m trying to setup a simple tool to measure different aspects of a system. I build a project which can log an accelerometer, gyroscope and a magnetometer. I want full control of the the program so I decided not to use any usr/local kind of libraries and keep all files in the project folder. All files all working. I want to make the structure of my program as follows: https://www.dropbox.com/s/59s3si8spvkdq98/filestructure.png (not enough REP). I don't have much experience in making Makefiles, except changing a few variables. I work in the Embedded environment and mostly with IDE's.
I tried building my project with the following Makefile:
# Project name
NAME = TEST
# Tools
CC = gcc
CFLAGS = -o
# Paths
DRV_PATH = drivers
SRC_PATH = src
LIB_PATH = libs
# includes
INCLUDES = -I $(DRV_PATH) -I $(LIB_PATH) -I $(SRC_PATH)
# what files do we need to compile?
# libraries
MY_LIB = $(LIB_PATH)/bcm2835.c
# main files
MAIN = main.c
# src files
#MY_SRC = $(SRC_PATH)/vector.c
MY_SRC += $(SRC_PATH)/dcm.c
# select drivers to compile
DRV_SRC = $(DRV_PATH)/adxl345.c
DRV_SRC += $(DRV_PATH)/itg3200.c
DRV_SRC += $(DRV_PATH)/hmc5883l.c
DRV_SRC += $(DRV_PATH)/gy-85.c
DRV_SRC += $(DRV_PATH)/nrf24l01.c
# bundle files
ALL_SRC = $(MY_LIB) $(DRV_SRC) $(MY_SRC) $(MAIN)
OBJ = $(ALL:.c=.o)
BIN = $(ALL:.c=)
# make commands
all:
$(CC) $(CFLAGS) $(NAME) $(ALL_SRC)
debug:
$(CC) $(CFLAGS) $(NAME) $(ALL_SRC) -DDEBUG=1
imudebug:
$(CC) $(CFLAGS) $(NAME) $(ALL_SRC) -DIMUDEBUG=1
nrfdebug:
$(CC) $(CFLAGS) $(NAME) $(ALL_SRC) -DNRFDEBUG=1
I use the different make commands to generate some debug output.
The config file currently includes all files and is as follows:
#ifndef CONFIG_H
#define CONFIG_H
/* includes */
#include <stdio.h>
#include <math.h>
/* libs */
#include <bcm2835.h>
/* drivers */
#include "gy-85.h"
#include "adxl345.h"
#include "itg3200.h"
#include "hmcl5883l.h"
#include "nrf24l01.h"
/* src */
#include "dcm.h"
#endif // __CONFIG_H__
And the dcm.h file looks as follows. I tried t keep all .h files like this:
#ifndef DCM_H
#define DCM_H
#include <bcm2835.h>
#include <stdio.h>
#include <math.h>
#include "gy-85.h"
double pitch, roll, yaw;
double DCM_Matrix[3][3];
uint64_t stamp;
void resetFusion(void);
#endif
This is my make result:
gcc -o TEST libs/bcm2835.c drivers/adxl345.c drivers/itg3200.c drivers/hmc5883l.c drivers/gy-85.c drivers/nrf24l01.c src/dcm.c main.c
In file included from drivers/adxl345.c:1:0:
drivers/adxl345.h:4:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
In file included from drivers/itg3200.c:1:0:
drivers/itg3200.h:4:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
drivers/hmc5883l.c: In function ‘magInit’:
drivers/hmc5883l.c:7:30: error: ‘MAG_ADDR’ undeclared (first use in this function)
drivers/hmc5883l.c:7:30: note: each undeclared identifier is reported only once for each function it appears in
drivers/hmc5883l.c:14:17: error: ‘MODE’ undeclared (first use in this function)
drivers/hmc5883l.c:14:23: error: ‘CONTINUOUS’ undeclared (first use in this function)
drivers/hmc5883l.c:22:17: error: ‘CONA’ undeclared (first use in this function)
drivers/hmc5883l.c:22:23: error: ‘RATE_50HZ’ undeclared (first use in this function)
drivers/hmc5883l.c: In function ‘magRead’:
drivers/hmc5883l.c:37:30: error: ‘MAG_ADDR’ undeclared (first use in this function)
drivers/hmc5883l.c:38:18: error: ‘DATA’ undeclared (first use in this function)
drivers/hmc5883l.c: In function ‘magGetRegister’:
drivers/hmc5883l.c:60:13: error: ‘BCM2835_I2C_REASON_OK’ undeclared (first use in this function)
drivers/hmc5883l.c:61:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
drivers/hmc5883l.c: At top level:
drivers/hmc5883l.c:71:6: warning: conflicting types for ‘magGetRegisters’ [enabled by default]
drivers/hmc5883l.c:38:2: note: previous implicit declaration of ‘magGetRegisters’ was here
drivers/hmc5883l.c: In function ‘magGetRegisters’:
drivers/hmc5883l.c:79:13: error: ‘BCM2835_I2C_REASON_OK’ undeclared (first use in this function)
drivers/hmc5883l.c:80:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
drivers/hmc5883l.c: At top level:
drivers/hmc5883l.c:97:6: warning: conflicting types for ‘magSetRegister’ [enabled by default]
drivers/hmc5883l.c:14:2: note: previous implicit declaration of ‘magSetRegister’ was here
drivers/hmc5883l.c: In function ‘magSetRegister’:
drivers/hmc5883l.c:107:13: error: ‘BCM2835_I2C_REASON_OK’ undeclared (first use in this function)
drivers/hmc5883l.c:108:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
drivers/gy-85.c: In function ‘gyInit’:
drivers/gy-85.c:15:30: error: ‘BCM2835_I2C_CLOCK_DIVIDER_2500’ undeclared (first use in this function)
drivers/gy-85.c:15:30: note: each undeclared identifier is reported only once for each function it appears in
drivers/gy-85.c: In function ‘gyUpdate’:
drivers/gy-85.c:29:2: error: unknown type name ‘int16_t’
drivers/gy-85.c:30:2: error: unknown type name ‘uint8_t’
drivers/gy-85.c:32:9: error: ‘int16_t’ undeclared (first use in this function)
drivers/gy-85.c:32:18: error: expected expression before ‘)’ token
drivers/gy-85.c:40:18: error: expected expression before ‘)’ token
drivers/gy-85.c:47:18: error: expected expression before ‘)’ token
drivers/gy-85.c:61:2: warning: return from incompatible pointer type [enabled by default]
In file included from drivers/nrf24l01.c:1:0:
drivers/nrf24l01.h:5:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
In file included from src/dcm.c:1:0:
src/dcm.h:4:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
In file included from main.c:1:0:
config.h:9:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
make: *** [all] Error 1
If you can point out the main problem with my file structure I would be so glad!
Current error list:
gcc -o TEST -I libs -I drivers -I src libs/bcm2835.c drivers/adxl345.c drivers/itg3200.c drivers/hmc5883l.c drivers/gy-85.c drivers/nrf24l01.c src/dcm.c main.c
drivers/gy-85.c: In function ‘gyUpdate’:
drivers/gy-85.c:63:2: warning: return from incompatible pointer type [enabled by default]
main.c: In function ‘main’:
main.c:51:4: warning: passing argument 1 of ‘nrf24Transmit’ from incompatible pointer type [enabled by default]
drivers/nrf24l01.h:145:9: note: expected ‘uint8_t *’ but argument is of type ‘uint64_t *’
/tmp/ccOWR401.o:(.bss+0x0): multiple definition of `accelRaw'
/tmp/cc1gy1Bh.o:(.bss+0x0): first defined here
/tmp/ccOWR401.o:(.bss+0x8): multiple definition of `accelBias'
/tmp/cc1gy1Bh.o:(.bss+0x8): first defined here
/tmp/ccyZlhJe.o:(.bss+0x0): multiple definition of `accelRaw'
/tmp/cc1gy1Bh.o:(.bss+0x0): first defined here
/tmp/ccyZlhJe.o:(.bss+0x8): multiple definition of `accelBias'
/tmp/cc1gy1Bh.o:(.bss+0x8): first defined here
/tmp/ccUbOIyA.o:(.bss+0x0): multiple definition of `accelRaw'
/tmp/cc1gy1Bh.o:(.bss+0x0): first defined here
/tmp/ccUbOIyA.o:(.bss+0x8): multiple definition of `accelBias'
/tmp/cc1gy1Bh.o:(.bss+0x8): first defined here
/tmp/ccyZlhJe.o: In function `resetFusion':
dcm.c:(.text+0x38): undefined reference to `atan2'
collect2: ld returned 1 exit status
make: *** [all] Error 1
You don't have your includes in your rule
INCLUDES = -I $(DRV_PATH) -I $(LIB_PATH) -I $(SRC_PATH)
This just seems to dangle. Simplest solution to my eyes is to move down your CFLAGS definition and add in the includes:
INCLUDES = -I $(DRV_PATH) -I $(LIB_PATH) -I $(SRC_PATH)
CFLAGS = -o $(INCLUDES)
This way you don't have to change anything else. Of course, there are alternatives, this one just looks easiest.

How to compile C version of vtd-xml under linux (32 bit)

I've downloaded ximpleware_2.11_c.zip (C version of vtd-xml), when I
have tried to compile it under linux I've the following error messages:
In file included from vtdNav.c:19:
vtdNav.h:82: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h:506: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h: In function ‘writeIndex_VTDNav’:
vtdNav.c: At top level:
vtdNav.c:3410: error: conflicting types for ‘writeIndex_VTDNav’
vtdNav.h:347: error: previous declaration of ‘writeIndex_VTDNav’ was here
vtdNav.c: In function ‘dumpXML’:
vtdNav.c:3554: error: too many arguments to function ‘dumpXML2’
vtdNav.c: At top level:
vtdNav.c:3562: error: conflicting types for ‘dumpXML2’
vtdNav.h:362: error: previous declaration of ‘dumpXML2’ was here
In file included from vtdNav.c:19:
vtdNav.h:82: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h:506: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h: In function ‘writeIndex_VTDNav’:
vtdNav.h:507: error: ‘f’ undeclared (first use in this function)
vtdNav.h:507: error: (Each undeclared identifier is reported only once
vtdNav.h:507: error: for each function it appears in.)
vtdNav.h:507: error: too many arguments to function
‘vn->__writeIndex_VTDNav’
vtdNav.h: At top level:
vtdNav.h:675: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h:695: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.c: In function ‘_writeIndex2_VTDNav’:
vtdNav.c:3751: error: too many arguments to function ‘writeIndex_VTDNav’
vtdNav.c: In function ‘dumpXML’:
vtdNav.c:3874: error: too many arguments to function ‘dumpXML2’
vtdNav.c: At top level:
vtdNav.c:3882: error: conflicting types for ‘dumpXML2’
vtdNav.h:695: error: previous declaration of ‘dumpXML2’ was here
make: *** [vtdNav.o] Error 1
How can I build it under linux ?
Thanks for your response.
I've put
#include <stdio.h>
in :
vtdNav.h and in transcoder.h
and now it compile.
I'm sorry to have put a post to ask how to compile the examples. I have compiled them by modifying the makefile already present in ximpleware_2.11_c and in this way works:
CC=gcc
CFLAGS= -c -O3 -Wall -Winline -fgnu89-inline -fomit-frame-pointer-fforce-addr -frerun-cse-after-loop -fexpensive-optimizations -fregmove -frerun-loop-opt -fmerge-all-constants -fno-branch-count-reg -funroll-loops -fpeephole -march=core2-falign-functions -falign-loops -falign-jumps -freorder-blocks -freorder-functions-fprefetch-loop-arrays -funswitch-loops -fbranch-target-load-optimize2 -fvpt --paraminline-unit-growth=300 --param max-inline-recursive-depth=2 --param large-function-growth=600
CFLAGS2 = -c -ggdb
LDFLAGS = -O3 -fomit-frame-pointer -fforce-addr -frerun-cse-after-loop-fexpensive-optimizations -fregmove -frerun-loop-opt -march=core2 -lm
LDFLAGS2 = -ggdb
all : hello_world
hello_world: hello_world.o ../../arrayList.o ../../fastIntBuffer.o ../../fastLongBuffer.o ../../contextBuffer.o ../../vtdNav.o ../../vtdGen.o ../../autoPilot.o ../../XMLChar.o ../../helper.o ../../lex.yy.o ../../l8.tab.o ../../literalExpr.o ../../numberExpr.o ../../pathExpr.o ../../filterExpr.o ../../binaryExpr.o ../../unaryExpr.o ../../funcExpr.o ../../locationPathExpr.o ../../intHash.o ../../unionExpr.o ../../decoder.o ../../XMLModifier.o ../../nodeRecorder.o ../../indexHandler.o ../../bookMark.o ../../elementFragmentNs.o ../../transcoder.o ../../textIter.o ../../variableExpr.o ../../cachedExpr.o
clean:
-rm *.o
hello_world.o : hello_world.c
${CC} ${CFLAGS} hello_world.c

Resources