0

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
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Sneftel Feb 18 '20 at 09:07
  • For your question to be complete, you should provide your compilation line. – Frodon Feb 18 '20 at 09:16
  • Ok I edited the post with the full output. I hope that is what you are looking for. I am new to C. – Andrew Goodman Feb 18 '20 at 13:03

0 Answers0