I have installed MPICH (ver 3.0.4) on my linux machine (CentOS 6.4) for doing some parallel computation. I tried to compile "pmandel.c" (which comes with MPICH installation package as an example) to test my MPICH installation with this command :
mpicc pmandel.c -o pmandel.out
but it returns these errors:
pmandel.c: In function ‘main’:
pmandel.c:279: warning: passing argument 2 of ‘bind’ from incompatible pointer type
/usr/include/sys/socket.h:115: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’
pmandel.c:282: warning: passing argument 2 of ‘bind’ from incompatible pointer type
/usr/include/sys/socket.h:115: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’
pmandel.c:296: warning: passing argument 2 of ‘getsockname’ from incompatible pointer type
/usr/include/sys/socket.h:119: note: expected ‘struct sockaddr * __restrict__’ but argument is of type ‘struct sockaddr_in *’
/tmp/cclNv8nA.o: In function `exponential_complex':
pmandel.c:(.text+0x2fc2): undefined reference to `exp'
pmandel.c:(.text+0x2fd1): undefined reference to `cos'
pmandel.c:(.text+0x2fe5): undefined reference to `sin'
/tmp/cclNv8nA.o: In function `absolute_complex':
pmandel.c:(.text+0x3330): undefined reference to `sqrt'
collect2: ld returned 1 exit status
and no output is made. I also tried with "mpic++", "mpiCC", mpicxx" ... but all to no avail.
what should I do to correct this?
#Spiros is correct that you need to add -lm to your mpicc. It matters where in the command you specify it, too.
"It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded."
see http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html.
It comes after pmandel.out.
mpicc pmandel.c -o pmandel.out -lm
Alternatively, you can use the Makefile included in the mpich examples directory and just type
make pmandel
Related
I'm trying to implement calling octave from C, as per the example shown in this answer Call GNU Octave functions in C?
I'm trying this in Nebeans on Linux.
I've created the files calloctave.cc, calloctave.h, main.c and myfunction.m as per the example. Pointed the links and includes to the correct places (in my case /usr/include/octave-5.2.0/octave/ and /usr/lib64/octave/5.2.0 ). I've chosen C++11 as the standard. In the code, there are no errors highlighted and it seems to find everything it needs, and nothing is highlighted as missing.
When I try to compile it, I just get a series of errors as follows....
cd '/home/arwel/NetBeansProjects/callOctave_new'
/bin/gmake -f Makefile CONF=Debug
"/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory `/home/arwel/NetBeansProjects/callOctave_new'
"/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/libcallOctave_new.so
gmake[2]: Entering directory `/home/arwel/NetBeansProjects/callOctave_new'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/calloctave.o.d"
g++ -c -g -I/usr/include/octave-5.2.0/octave -include /usr/include/octave-5.2.0/octave/mex.h -std=c++11 -fPIC -MMD -MP -MF "build/Debug/GNU-Linux/calloctave.o.d" -o build/Debug/GNU-Linux/calloctave.o calloctave.cc
In file included from /usr/include/octave-5.2.0/octave/Cell.h:33:0,
from /usr/include/octave-5.2.0/octave/gtk-manager.h:32,
from /usr/include/octave-5.2.0/octave/interpreter.h:36,
from calloctave.cc:7:
/usr/include/octave-5.2.0/octave/ov.h:52:7: error: using typedef-name ‘mxArray’ after ‘class’
class mxArray;
^
In file included from <command-line>:0:0:
/usr/include/octave-5.2.0/octave/mex.h:55:14: note: ‘mxArray’ has a previous declaration here
typedef void mxArray;
^
In file included from /usr/include/octave-5.2.0/octave/ov.h:62:0,
from /usr/include/octave-5.2.0/octave/Cell.h:33,
from /usr/include/octave-5.2.0/octave/gtk-manager.h:32,
from /usr/include/octave-5.2.0/octave/interpreter.h:36,
from calloctave.cc:7:
/usr/include/octave-5.2.0/octave/ov-base.h:57:7: error: using typedef-name ‘mxArray’ after ‘class’
class mxArray;
^
In file included from <command-line>:0:0:
/usr/include/octave-5.2.0/octave/mex.h:55:14: note: ‘mxArray’ has a previous declaration here
typedef void mxArray;
^
calloctave.cc: In function ‘int mexCallOctave(int, mxArray**, int, mxArray**, const char*)’:
calloctave.cc:26:15: error: ‘mxArray’ is not a class, namespace, or enumeration
args(i) = mxArray::as_octave_value (argin[i]);
^
calloctave.cc:42:41: error: invalid use of ‘mxArray {aka void}’
argout[i] = new mxArray (retval(i));
^
calloctave.cc: In function ‘void free_arg_list(int, mxArray**)’:
calloctave.cc:56:29: warning: deleting ‘mxArray* {aka void*}’ is undefined [enabled by default]
delete arglist[i];
^
gmake[2]: *** [build/Debug/GNU-Linux/calloctave.o] Error 1
gmake[2]: Leaving directory `/home/arwel/NetBeansProjects/callOctave_new'
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory `/home/arwel/NetBeansProjects/callOctave_new'
gmake: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
It seems to be not understanding the mex interface in some way. I'm not very knowledgeable about C/C++, so am at a loss as to how to proceed here. What could be causing these errors and how might I resolve them?
Not a duplicate; Answers on various forums didn't fix the problem.
I am running GCC through commands and I am getting undefined references from SDL even though it appears like I linked SDL correctly, how do I stop from getting those undefined references ?
I do not get undefined references from mingw, just SDL.
This is my command: (all the libraries are being located by GCC from what I can tell)
gcc main.c ^
-o app.exe ^
-I "C:\__coding\tools\SDL2-2.0.10\x86_64-w64-mingw32\include\SDL2" ^
-L "C:\__coding\tools\MinGW\lib\" ^
-l "libmingw32.a" ^
-L "C:\__coding\tools\SDL2-2.0.10\x86_64-w64-mingw32\lib" ^
-l "libSDL2main.a" ^
-l "libSDL2.a"
This is the output:
C:...\main.c:(.text+0xe): undefined reference to 'SDL_Init'
C:...\main.c:(.text+0x13): undefined reference to 'SDL_Quit'
c:/__coding/tools/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccqsLSRk.o: bad reloc address 0x20 in section '.eh_frame'
c:/__coding/tools/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
main.c includes SDL.h and just runs SDL_Init() and SDL_Quit().
I also get the classic undefined reference to "winmain" when I remove SDL_Init() and SDL_Quit().
Thanks alot.
I've been trying to get mruby set up for use in C, but I've only had success compiling a simple "hello world" example. Other examples won't compile: when I try to compile https://github.com/mruby/mruby/blob/master/tools/mrbc/mrbc.c, I get this:
gcc -Iinclude hello.c libmruby_core.a libmruby.a -lm -o hello
hello.c: In function ‘parse_args’:
hello.c:119:24: error: ‘DUMP_DEBUG_INFO’ undeclared (first use in this function)
args->flags |= DUMP_DEBUG_INFO;
^
hello.c:119:24: note: each undeclared identifier is reported only once for each function it appears in
hello.c:122:23: error: ‘DUMP_ENDIAN_BIG’ undeclared (first use in this function)
args->flags = DUMP_ENDIAN_BIG | (args->flags & DUMP_DEBUG_INFO);
^
hello.c:125:23: error: ‘DUMP_ENDIAN_LIL’ undeclared (first use in this function)
args->flags = DUMP_ENDIAN_LIL | (args->flags & DUMP_DEBUG_INFO);
^
hello.c:154:57: error: ‘DUMP_ENDIAN_MASK’ undeclared (first use in this function)
if (args->verbose && args->initname && (args->flags & DUMP_ENDIAN_MASK) == 0) {
When I try to compile the 'more complex example' from http://matt.aimonetti.net/posts/2012/04/25/getting-started-with-mruby/, in the way they suggest (gcc -Iinclude hello.c lib/libmruby.a -lm -o hello.out) (actually: in a similar way. I've tried both ways.) I get this:
gcc -Iinclude hello.c libmruby.a -lm -o hellohello.c: In function ‘main’:
hello.c:17:7: error: too few arguments to function ‘mrb_parse_string’
p = mrb_parse_string(mrb, code);
^
In file included from /home/neo/Projects/MrubyHs/mruby-1.1.0/include/mruby/irep.h:14:0,
from /home/neo/Projects/MrubyHs/mruby-1.1.0/include/mruby/proc.h:10,
from hello.c:6:
/home/neo/Projects/MrubyHs/mruby-1.1.0/include/mruby/compile.h:170:34: note: declared here
MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
^
hello.c:19:5: warning: assignment makes integer from pointer without a cast
n = mrb_generate_code(mrb, p);
^
hello.c:20:37: error: ‘mrb_state’ has no member named ‘irep’
mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
^
Looks like I'm missing some file or something, but I'm not sure what.
I'm using mruby 1.1.0. I have mruby-1.1.0/include which contains mrbconf.h, mruby.h, and a folder mruby in the gcc search path, and mruby-1.1.0/build/host/lib in LIBRARY_PATH (even though in my examples of what went wrong I just put them in the same folder as where I'm compiling).
Any idea what's wrong with my installation and/or how I'm compiling?
You are trying to compile a newer version of mrbc.c with an older version of mruby. Those #defines were added after 1.1.0 was released. It works for me if I use the version of mruby currently in the git repo:
$ make
...
$ gcc -Iinclude build/host/lib/libmruby.a mrbc.c
$ ./a.out
./a.out: no program file given
As for the second problem, mrb_parse_string was changed to accept an mrb_context* as the third argument in July 2012, so you may want to look into updating your code to use the new API.
I get a strange compiler warning when i use the reader-writer spinlock as below,
defined in a.c
struct rwloct_t rwspinlock.
rwlock_init(&rwspinlock);
using in b.c by declaring
extern struct rwloct_t rwspinlock
So, in b.c whenever i call lock or unlock, eg.read_rwlock(&rwspinlock) i get the below warning.
warning: passing argument 1 of ‘_raw_read_lock_bh’ from incompatible pointer type
/home/dev/data/linux/linux/include/linux/rwlock_api_smp.h:20: note: expected ‘struct rwlock_t *’ but argument is of type ‘struct rwlock_t *’
Then, I changed as below,
defined in a.c
struct rwloct_t rwspinlock.
rwlock_init(&rwspinlock);
declared in a.h
extern struct rwloct_t rwspinlock
included in b.c as,
#include "a.h"
Now there is no compilation warning. However, i'm unclear how!.
Can anybody explain, what exactly happened ?
Maybe your rwloct_t is already defined (typedef) as a struct (here the _t suffix)?
If so you don't need to use struct again:
rwloct_t rwspinlock;
extern rwloct_t rwspinlock;
Why it work within .h and not .c? I don't know, but you may try to precompile both with gcc and the option -E and see if there's some difference, else I guess is some compiler internal reason.
I've just upgraded my app from 1.8.7 to 1.9.2 using RVM and had to add RubyGems and Bundler, ran bundle install and got everything to work except SystemTimer. Google-fu returns nothing and I see others have had issue with it in 1.9 but some have gotten it to work. Any ideas?
pawel:bodb pawel$ sudo gem install SystemTimer
Building native extensions. This could take a while...
/Users/pawel/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
ERROR: Error installing SystemTimer:
ERROR: Failed to build gem native extension.
/Users/pawel/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
creating Makefile
make
/usr/bin/gcc-4.2 -I. -I/Users/pawel/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-darwin10.3.0
-I/Users/pawel/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/Users/pawel/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I.
-D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers
-Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -o system_timer_native.o -c system_timer_native.c
In file included from system_timer_native.c:8:
/Users/pawel/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward/rubysig.h:14:2: warning: #warning rubysig.h is obsolete
system_timer_native.c: In function ‘install_first_timer_and_save_original_configuration’:
system_timer_native.c:46: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:53: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:57: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:62: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:65: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:69: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:82: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:89: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:96: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:101: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c: In function ‘install_next_timer’:
system_timer_native.c:112: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:119: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:123: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:130: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:136: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:143: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:146: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c: In function ‘restore_original_configuration’:
system_timer_native.c:157: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:160: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:168: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:170: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:172: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c: In function ‘restore_original_timer_interval’:
system_timer_native.c:190: warning: passing argument 1 of ‘log_error’ discards qualifiers from pointer target type
system_timer_native.c:192: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c: In function ‘restore_sigalrm_mask’:
system_timer_native.c:199: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:201: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c: In function ‘install_ruby_sigalrm_handler’:
system_timer_native.c:211: error: ‘rb_thread_critical’ undeclared (first use in this function)
system_timer_native.c:211: error: (Each undeclared identifier is reported only once
system_timer_native.c:211: error: for each function it appears in.)
system_timer_native.c: In function ‘restore_original_ruby_sigalrm_handler’:
system_timer_native.c:217: error: ‘rb_thread_critical’ undeclared (first use in this function)
system_timer_native.c: In function ‘clear_pending_sigalrm_for_ruby_threads’:
system_timer_native.c:266: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c: In function ‘set_itimerval’:
system_timer_native.c:290: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
system_timer_native.c:295: warning: implicit conversion shortens 64-bit value into a 32-bit value
system_timer_native.c:299: warning: passing argument 1 of ‘log_debug’ discards qualifiers from pointer target type
make: *** [system_timer_native.o] Error 1
Gem files will remain installed in /Users/pawel/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/SystemTimer-1.2.3 for inspection.
Results logged to /Users/pawel/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/SystemTimer-1.2.3/ext/system_timer/gem_make.out
As far as I know, SystemTimer isn't relevant for ruby 1.9 and shouldn't use with this version.
"Using this gem in Ruby 1.9 is useless and does not make any sense! System Timer is trying to work around some limitation of the "green thread" model used in Ruby 1.8 (MRI). See http://ph7spot.com/musings/system-timer for more details."
A drop-in replacement for SystemTimer is timeout.rb from Ruby core. No need for any 3rd party gems.
Ruby 1.8:
require 'system_timer'
SystemTimer.timeout_after(5.minutes, MyException) do
# your job here
end
Ruby 1.9:
require 'timeout'
Timeout.timeout(5.minutes, MyException) do
# your job here
end
To install system timer use this command in Terminal:
sudo gem install system_timer