I am trying to compile my project for the university, everything worked fine until I had to use the sin() function. I get the error:
/home/patrick/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/181.4668.70/bin/cmake/bin/cmake --build /home/patrick/CLionProjects/Aufgabe4_TEI2/cmake-build-debug --target TEI2_A3 -- -j 2
[ 33%] Linking C executable TEI2_A3
CMakeFiles/TEI2_A3.dir/resources/wave.c.o: In Funktion »berechneSignalWert«:
/home/patrick/CLionProjects/Aufgabe4_TEI2/resources/wave.c:38: Warnung: undefinierter Verweis auf »sin«
collect2: error: ld returned 1 exit status
CMakeFiles/TEI2_A3.dir/build.make:120: recipe for target 'TEI2_A3' failed
make[3]: *** [TEI2_A3] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/TEI2_A3.dir/all' failed
make[2]: *** [CMakeFiles/TEI2_A3.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/TEI2_A3.dir/rule' failed
make[1]: *** [CMakeFiles/TEI2_A3.dir/rule] Error 2
Makefile:118: recipe for target 'TEI2_A3' failed
make: *** [TEI2_A3] Error 2
The project is a Cmake-Project, I have tried the answers out of this post: CLion CMakeLists.txt add argv arguments to configuration but they did not work. Below my CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(TEI2_A3 C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "-lm")
include_directories(.)
include_directories(./../Aufgabe4_TEI2)
add_executable(TEI2_A3
test.wav
main.c resources/wave.h resources/wave.c)
You can one of my tries still in there. I know the problem about the , but I couldn't solve it yet. Does anyone have an idea how to do this in CLion?
My file looks like this
#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.1415926535897932384626433832795028841971
#include "wave.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
void writePCM(char * name, float *signal, int N, wavheader header)
{
FILE *fileOut = fopen(name,"wb");
chunkheader dataheader;
header.riff_chunk_header.chunk_size =
/*Größe chunks RIFF+fmt */ sizeof(header)/*36*/ - sizeof(chunkheader) /*8*/ /*subchunk header RIFF zählt nicht mit*/ +
/*Größe subchunk data*/ sizeof(chunkheader) /*8*/ + N*4 ;
fwrite(&header,sizeof(header),1,fileOut);
strncpy(dataheader.chunk_id,"data",4);
dataheader.chunk_size=N*4;
fwrite(&dataheader,sizeof(dataheader),1,fileOut);
fwrite(signal,4,N,fileOut);
fclose(fileOut);
}
//Mittelwert der Sample_Rate: 6595.007324
float mittelWert(float* array){
float sum = 0;
printf("Number of entries: %f\n", array[0]);
for (int j = 1; j < array[0]; ++j) {
sum += fabs(array[j] - j-1);
}
return sum/array[0];
}
float berechneSignalWert(float n, float f, float a, float r){
return (float) sin(f * 2 * M_PI * (n / r));
}
float* sinusSignal(float* N, float frequenz, float amplitude, float Abtastrate){
float* array;
for (int n = 1; n <= N[0]; ++n) {
array[n] = berechneSignalWert(n, frequenz, amplitude, Abtastrate);
}
return array;
}
The function berechneSignalWert returns the error on the sin() call