failure linking C code - c

I a ma total noob in C programming. I took some code that throws this error when I run make :
Undefined symbols for architecture x86_64:
"_rp_osc_adc_sign", referenced from:
_rp_osc_meas_min_max in worker.o
_meas_period in worker.o
"_rp_osc_meas_cnv_cnt", referenced from:
_rp_osc_meas_convert in worker.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [make_c_app] Error
I am using OS X Yosemite and here's the make file
CC=$(CROSS_COMPILE)gcc
RM=rm
OBJECTS=main.o fpga.o worker.o calib.o fpga_awg.o generate.o fpga_pid.o pid.o
INCLUDE=
#CFLAGS=$(CFLAGS) -Wall -Werror -g
CFLAGS+= -Wall -Werror -g -fPIC $(INCLUDE)
LDFLAGS=-shared
OUT_DIR=../
C_OUT_NAME=$(OUT_DIR)controller.so
all: make_c_app
clean: clean_c_app
make_c_app: $(OBJECTS)
$(CC) -o $(C_OUT_NAME) $(OBJECTS) $(CFLAGS) $(LDFLAGS)
clean_c_app:
$(RM) -f $(C_OUT_NAME) $(OBJECTS)
and the method the linker is complaining about
int rp_osc_meas_min_max(rp_osc_meas_res_t *ch_meas, int sig_data)
{
int s_data = rp_osc_adc_sign(sig_data);
if(ch_meas->min > s_data)
ch_meas->min = s_data;
if(ch_meas->max < s_data)
ch_meas->max = s_data;
ch_meas->avg += s_data;
return 0;
}
Where the error can come from ?
EDIT : rp_osc_adc_sign is defined the following way
inline int rp_osc_adc_sign(int in_data)
{
int s_data = in_data;
if(s_data & (1<<(c_osc_fpga_adc_bits-1)))
s_data = -1 * ((s_data ^ ((1<<c_osc_fpga_adc_bits)-1)) + 1);
return s_data;
}

You should delete the inline tag that is written before the function
rp_osc_adc_sign(int in_data)
rp_osc_meas_cnv_cnt

Related

Wierd error while compiling my program and a module using makefile

This is the error when I run make:
Undefined symbols for architecture arm64:
"\_add", referenced from:
\_main in a4-1-989722.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: \*\*\* \[a4-1\] Error 1
note (one of the functions in my module is add()
This is the makefile:
CC = gcc
CFLAGS = -Wall -Wextra -pedantic
TARGET = a4-1
DEP1 = myMath
all: $(TARGET)
debug: CFLAGS += -DDBUG
debug: $(TARGET)
&(TARGET): $(TARGET).c $(DEP1).o
$(CC) $(CFLAGS) $(DEP1).o -o $(TARGET) $(TARGET).c
$(DEP1).o: $(DEP1).c
$(CC) $(CFLAGS) -c $(DEP1).c
clean:
rm $(TARGET) *.o
This is the module .c file:
#include <stdio.h>
#include <stdlib.h>
int add(int x, int y)
{
return(x + y);
}
This is the module .h file:
int add(int, int);
#include "module.h"
in module.c

Did a Mac update ruin my ability to use gcc?

I am trying to compile two c files into one executable. In the directory I have only three files; Makefile, main.c and myfunction.c.
Makefile:
CC = gcc
CFLAGS = -Wall -g -O0
LIBS = -lm
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)
MAIN = main
all: $(MAIN)
#echo Program has been compiled
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LIBS)
clean:
$(RM) *.o *~ $(MAIN)
main.c:
#include <stdio.h>
void myfunc();
int main (int argc, char *argv[]) {
myfunc();
return 0;
}
myfunction.c:
#include <stdio.h>
void myfunc() { printf("hello world"); }
output after make:
gcc -Wall -g -O0 -c -o main.o main.c
gcc -Wall -g -O0 -c -o myfunction.o myfunction.c
gcc -Wall -g -O0 -o main main.o myfunction.o -lm
Undefined symbols for architecture x86_64:
"_myfunc", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
I had something nearly identical working in the past. I have since clean installed MacOS and updated to Big Sur. Is this the issue or have I overlooked something?
I fixed the issue. I’m not sure what part fixed it, but installed Homebrew and used it to install gcc-10. I also deleted the project and started over.
myfunc would define like file header
myfunc.h
void myfunc()
Declare in another file
myfunc.c
void myfunc() { printf("hello world"); }
Follow the following tutorial
https://developer.gnome.org/anjuta-build-tutorial/stable/build-make.html.en

undefined references when using fftw3.3.6 with threads and float enabled

I installed fftw3.3.6 on my Ubuntu 16.04 to test the performance of using this library with thread and float enabled.
Step 1 :
Installed the library with thread and float and SIMD instructions enabled:`
sudo ./configure --enable-float --enable-generic-simd128 --enable-generic-simd256 --enable-threads
make
make install
Step 2 :
I wrote this code (basing on the manual and tutorial) to compute an fft of 1024 points using 4 threads (complex to complex):
#include <stdio.h>
#include <stdlib.h>
#include <fftw3.h>
#include "input.h"
#define NUMBER_OF_ELEMENTS 1024
#define NUM_THREADS 4
void Load_inputs(fftwf_complex* data)
{
int i;
for(i=0;i<NUMBER_OF_ELEMENTS;i++)
{
data[i][0] = input_data[2 * i];
data[i][1] = input_data[2 * i + 1];
}
}
int main()
{
fftwf_complex array[NUMBER_OF_ELEMENTS];
fftwf_plan p;
int i;
fftwf_init_threads();
fftwf_plan_with_nthreads(NUM_THREADS);
p = fftwf_plan_dft(1,NUMBER_OF_ELEMENTS,array,array,FFTW_FORWARD,FFTW_EXHAUSTIVE);
Load_inputs(array); //function to load input data from input.h file to array[]
fftwf_execute(p);
FILE* res = NULL;
res = fopen("result.txt", "w");
for ( i = 0; i <1024; i++ )
{
fprintf(res,"RE = %f \t IM = %f\n",array[i][0], array[i][1] );
}
fclose(res);
fftwf_destroy_plan(p);
fftwf_cleanup_threads();
}
And then, I compiled this program with this makefile.
CC=gcc
CFLAGS=-g3 -c -Wall -O0 -mavx -mfma -ffast-math
SOURCES=$ test.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=test
all: $(TASKMAP) $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o $# -L -lfftw3f_threads -lfftw3f
.c.o:
$(CC) $(CFLAGS) $< -lm -o $#
clean:
rm -fr $(OBJECTS) $(EXECUTABLE)
Compilation errors :
After compilation I've got these errors:
gcc test.o -o test -L -lfftw3f_threads -lfftw3f
//usr/local/lib/libfftw3f.a(mapflags.o): In function `fftwf_mapflags':
mapflags.c:(.text+0x346): undefined reference to `__log_finite'
Makefile:13: recipe for target 'test' failed
//usr/local/lib/libfftw3f.a(trig.o): In function `cexpl_sincos':
trig.c:(.text+0x2c1): undefined reference to `sincos'
//usr/local/lib/libfftw3f.a(trig.o): In function `fftwf_mktriggen':
trig.c:(.text+0x50b): undefined reference to `sincos'
trig.c:(.text+0x653): undefined reference to `sincos'
test.o: In function `main':
/home/anouar/workspace/Thread_example//test.c:27: undefined reference to `fftwf_init_threads'
/home/anouar/workspace/Thread_example//test.c:28: undefined reference to `fftwf_plan_with_nthreads'
/home/anouar/workspace/Thread_example//test.c:40: undefined reference to `fftwf_cleanup_threads'
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
Is there something missing, or something wrong that I have did during installation and compilation?
Read the fine manual. From the sincos() man page:
Link with -lm.
Using -lm in the compile phase of your program is useless:
.c.o:
$(CC) $(CFLAGS) $< -lm -o $#
-lm needs to be in the link stage:
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o $# -L -lfftw3f_threads -lfftw3f -lm
In my case, the problems with
undefined reference to `__log_finite'
could be solved by compiling without the -ffast-math option.

Trying to use matlab's libmat.dll, but the compiler doesn't recognize the function from the library

I am trying to use matlab libmat.dll in a C application. To compile my C application I use MinGW, for now I use matlab exemple "matcreate.c" and try to compile it, so the projects consist of only one file : main.c .
Here is the makefile I use :
MATINCLUDE = "C:\Program Files\MATLAB\R2010a\extern\include"
MATLIBRARY = "C:\Program Files\MATLAB\R2010a\bin\win64"
#
CC = gcc
LD = gcc
CFLAGS = -O3 -Wall
LFLAGS = -Wall -O3
LIBS = -I$(MATINCLUDE) -L$(MATLIBRARY)
#
PROG = matTest
LISTEOBJ = \
main.o
.c.o :
$(CC) -c $(CFLAGS) $(LIBS) -o $# $<
all : $(PROG)
$(PROG) : $(LISTEOBJ)
$(LD) -o $(PROG) $(LFLAGS) $(LISTEOBJ) $(LIBS)
clean :
rm -f *.obj
Here is what I get in the console
E:\Users\Desk\Dropbox\matTest>make
gcc -c -O3 -Wall -I"C:\Program Files\MATLAB\R2010a\extern\include" -L"C:\Pr
ogram Files\MATLAB\R2010a\bin\win64" -o main.o main.c
gcc -o Hello_world -Wall -O3 main.o -I"C:\Program Files\MATLAB\R2010a\extern\i
nclude" -L"C:\Program Files\MATLAB\R2010a\bin\win64"
main.o:main.c:(.text.startup+0x48): undefined reference to `matOpen'
main.o:main.c:(.text.startup+0x6e): undefined reference to `mxCreateDoubleMatrix
_730'
e:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: main.o: ba
d reloc address 0x6e in section `.text.startup'
e:/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
make: *** [Hello_world] Error 1
Why do I have "undefined reference to matOpen'" and "undefined reference to mxCreateDoubleMatrix" ?? those function are declared in mat.h. and I added #include "mat.h" to the begining of main.c
thank you
Looks like you have included the path to the matlab library, but not the library itself. You need to add a -l<libraryname> to your link line.

Undefined symbol _main, however I do have a main function?

Here is my console output:
Tylers-MacBook-Pro:laser_finder_c tylerjw$ make
gcc -g -Wall -c -o dots_img.o dots_img.c
gcc -g -Wall -c -o no_dots_img.o no_dots_img.c
gcc -g -Wall -c -o point.o point.c
gcc -g -Wall -c -o images.o images.c
gcc -g -Wall -c -o laser_finder_c.o laser_finder_c.c
gcc dots_img.o no_dots_img.o point.o images.o laser_finder_c.o -g -Wall -o laser_finder_c
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [laser_finder_c] Error 1
This doesn't seem to make any sense as the main function is defined in laser_finder_c.c. Below is my makefile. I'm real confused as to why this is happening.
TARGET = laser_finder_c
OBJECTS = dots_img.o no_dots_img.o point.o images.o laser_finder_c.o
#######################################################################################
CFLAGS = -g -Wall
ASFLAGS = -Wall
LDFLAGS = -g -Wall
CC = gcc
AS = gcc
########################################################################################
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $(TARGET)
point.o: point.h
images.o: images.h
laser_finder_c.o: images.h point.h
dots_img.o: images.h
no_dots_img.o: images.h
clean:
rm -f $(OBJECTS) $(TARGET)
Here is the definition of main in laser_finder_c.c
// laser_finder.c - finds the location of laser points comparing two images
#include "point.h"
#include <stdio.h>
#include <stdlib.h>
// #defines ... removed
int main()
{
// ... code removed
return 0;
}
For context the output of gcc -v is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

Resources