0

I'm trying to work with my header files in c. When i use code blocks, it handles the header include part, but in vs code, i couldn't figure it out yet. this is what i get in vs code. The files are in the same folder. I am using gcc.

#include "assPQ.h"

. . .

PS C:\Users\xxx\Desktop\xxxx\ass> cd "c:\Users\xxx\Desktop\xxxx\ass\" ; if ($?) { gcc coffeeShopSimulator.c -o coffeeShopSimulator } ; if ($?) { .\coffeeShopSimulator }
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\xxx\AppData\Local\Temp\cc6RasGF.o:coffeeShopSimulator.c:(.text+0xf): undefined reference to `CreateListPQ'
Nightingale
  • 133
  • 1
  • 7
  • "work with my header files" or using libraries? – Yunnosch Nov 14 '19 at 21:45
  • looks like your header files are squared away, it's the linker complaining that it can't find the binary code to the `CreateListPQ` function: https://stackoverflow.com/questions/22426574/gcc-undefined-reference-to – yano Nov 14 '19 at 21:45
  • i am writing the headers. assPQ.h and assPQ.c used in main.c then i got the error message. – Nightingale Nov 14 '19 at 21:55
  • What's your build line? You need to include the assPQ.c file like "gcc assPQ.c main.c" – yano Nov 14 '19 at 21:59
  • `{ "type": "shell", "label": "gcc.exe build active file", "command": "C:\\MinGW\\bin\\gcc.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:\\MinGW\\bin" }, "problemMatcher": [ "$gcc" ], "group": "build" }` you mean this ? – Nightingale Nov 14 '19 at 22:04
  • Perhaps .. I'm not familiar with VSCode. If it's anything like Visual Studio, there should be some support for adding all the source files you want to compile. Somehow, assPQ.c is getting left out. – yano Nov 14 '19 at 22:12

1 Answers1

0

i fixed the problem, probably because VS code is not an IDE you can only link by doing this

#include "header.c"

in the main.

What happens in the header itself is you need to link the "header.h" into "header.c" and "header.c" linked into "main.c".

Hopefully, this will help any other person. If there is another technical explanation, I'm happy to hear.

Nightingale
  • 133
  • 1
  • 7