Issue
I am new to C hence apologies for a simple question.
I am using code of statistics library in C with following commands:
gcc -Wall -I/usr/local/include -c statlib.c
It creates statlib.o
. Similar for other files.
Current list of files are:
$ ls -ltrh
total 112K
-rw-r--r-- 1 auser auser 2.1K Oct 1 20:41 nprob.c
-rw-r--r-- 1 auser auser 1.5K Oct 1 20:42 regtest.c
-rw-r--r-- 1 auser auser 32K Oct 1 20:43 statlib.c
-rw-r--r-- 1 auser auser 7.4K Oct 1 20:43 statlib.h
-rw-r--r-- 1 auser auser 3.7K Oct 1 20:47 stattest.c
-rw-r--r-- 1 auser auser 33K Oct 1 20:51 statlib.o
-rw-r--r-- 1 auser auser 7.6K Oct 1 20:56 stattest.o
-rw-r--r-- 1 auser auser 3.9K Oct 1 21:00 regtest.o
-rw-r--r-- 1 auser auser 5.1K Oct 1 21:01 nprob.o
But when I use following command to create stattest
executable, I get errors:
$ gcc stattest.c
/usr/bin/ld: /tmp/cckj2CHi.o: in function `main':
stattest.c:(.text+0x12d): undefined reference to `sum'
/usr/bin/ld: stattest.c:(.text+0x14a): undefined reference to `min_max'
/usr/bin/ld: stattest.c:(.text+0x162): undefined reference to `range'
/usr/bin/ld: stattest.c:(.text+0x17f): undefined reference to `a_mean'
/usr/bin/ld: stattest.c:(.text+0x19c): undefined reference to `g_mean'
/usr/bin/ld: stattest.c:(.text+0x1b9): undefined reference to `h_mean'
/usr/bin/ld: stattest.c:(.text+0x1d6): undefined reference to `tukeys_trimean'
/usr/bin/ld: stattest.c:(.text+0x1ff): undefined reference to `trimmed_mean'
/usr/bin/ld: stattest.c:(.text+0x21c): undefined reference to `midrange'
/usr/bin/ld: stattest.c:(.text+0x239): undefined reference to `median'
/usr/bin/ld: stattest.c:(.text+0x25f): undefined reference to `percentile'
/usr/bin/ld: stattest.c:(.text+0x27c): undefined reference to `quartiles'
/usr/bin/ld: stattest.c:(.text+0x294): undefined reference to `interquartile_range'
/usr/bin/ld: stattest.c:(.text+0x2b1): undefined reference to `mode'
/usr/bin/ld: stattest.c:(.text+0x2ce): undefined reference to `svar'
/usr/bin/ld: stattest.c:(.text+0x2ee): undefined reference to `pvar'
/usr/bin/ld: stattest.c:(.text+0x30e): undefined reference to `rms'
/usr/bin/ld: stattest.c:(.text+0x32e): undefined reference to `p_stdev'
/usr/bin/ld: stattest.c:(.text+0x34e): undefined reference to `s_stdev'
/usr/bin/ld: stattest.c:(.text+0x36e): undefined reference to `coeff_var'
/usr/bin/ld: stattest.c:(.text+0x38e): undefined reference to `mean_dev'
/usr/bin/ld: stattest.c:(.text+0x3ae): undefined reference to `std_err_mean'
/usr/bin/ld: stattest.c:(.text+0x3ce): undefined reference to `skewness1'
/usr/bin/ld: stattest.c:(.text+0x3ee): undefined reference to `skewness2'
/usr/bin/ld: stattest.c:(.text+0x40e): undefined reference to `kurtosis1'
/usr/bin/ld: stattest.c:(.text+0x42e): undefined reference to `kurtosis2'
/usr/bin/ld: stattest.c:(.text+0x44e): undefined reference to `chi_square'
/usr/bin/ld: stattest.c:(.text+0x46e): undefined reference to `confidence_95'
/usr/bin/ld: stattest.c:(.text+0x489): undefined reference to `confidence_99'
collect2: error: ld returned 1 exit status
Why can't I create a executable? Where is the problem but how can it be solved?
Solution
instead of running:
gcc stattest.c
run it with all the files you have already compiled:
gcc statlib.o stattest.o regtest.o nprob.o -o stattest
(the last -o stattest
will name the output program as stattest
, and not the default name used by the compiler --a.out
)
Answered By - Luis Colorado Answer Checked By - Cary Denson (WPSolving Admin)