I've been having a really annoying error in school project with defining libraries and then not being able see them when compiling. I've made a simpler program here that gets the same error.
main.c
#include "Util.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv){
printf("I'm in main\n");
someFunc();
return 0;
}
Util.c
#include "cmake-build-debug/Util.h"
#include <stdlib.h>
void someFunc(){
printf("I'm in someFunc\n");
};
Util.h
#ifndef UTIL_H
#define UTIL_H
void someFunc();
#endif
Output:
====================[ Build | untitled1 | Debug ]===============================
/snap/clion/103/bin/cmake/linux/bin/cmake --build /home/andrew/CLionProjects/untitled1/cmake-build-debug --target untitled1 -- -j 1
[ 50%] Linking C executable untitled1
CMakeFiles/untitled1.dir/main.c.o: In function `main':
/home/andrew/CLionProjects/untitled1/main.c:7: undefined reference to `someFunc'
collect2: error: ld returned 1 exit status
CMakeFiles/untitled1.dir/build.make:83: recipe for target 'untitled1' failed
make[3]: *** [untitled1] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/untitled1.dir/all' failed
make[2]: *** [CMakeFiles/untitled1.dir/all] Error 2
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/untitled1.dir/rule' failed
make[1]: *** [CMakeFiles/untitled1.dir/rule] Error 2
Makefile:118: recipe for target 'untitled1' failed
make: *** [untitled1] Error 2