1

I'm writing my first makefile. I wanted to link 2 files together. test.c and main.c. test.c includes a test.h as well as a header file, conio.h.

So far I've tried adding the header file to the paths returned after the failing make command, as well as adding the path to the header file in the command itself. For reference I'm using git bash. To add the make command to git bash I needed to add it directly to the bin folder of gits mingw, but it is looking program files x86 / mingw, which also contains conio.h

Do I need to link it to some kind of library instead. Any help in the matter would be appreciated.

gcc main.o test.o -o test -lconio
C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lconio
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:7: main] Error 1

main.c

#include "test.h"

int main() {
    char c = inputChar();
    return 0;
}

test.c

#include "test.h"
#include <conio.h>

void printChar(char casd) 
{
    _putch(casd);
}

void printString(const char *c) {
    for (const char* s = c; *s != 0; s++) {
        printChar(*s);
    }
    printChar('\n');
}

char inputChar() {
    char c = _getch();
    printChar(c);
    return c;
}

test.h

void printChar(char);
void printString(const char *c);
char inputChar();
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • conio.h (haven't seen that since I used Borland C; console input output, I think) is not part of the standard library. You should consider using stdio.h functions. No need for -l anything on the standard libraries; the compiler already does that for you – Mirko Sep 12 '19 at 02:31
  • https://en.wikipedia.org/wiki/Conio.h -> avoid conio.h, use standard, platform-independent functions instead – Mirko Sep 12 '19 at 02:32
  • 2
    Shouldn't need to link anything under Windows to get conio, or at least what's still supported in it. Remove the `-lconio` and let's see what sorts of error messages you're really getting. – user4581301 Sep 12 '19 at 02:56
  • 1
    @user4581301 thanks! I'm an idiot, I didn't need it in the first place. Thanks dude – user3475916 Sep 12 '19 at 03:33
  • Please be more exact the next time. You don't **link** anything to a makefile, you link together object files and libraries. And it is **not** make which returns the error, it's the linker, as the output clearly states. Finally, if you suspect the makefile to be erroneous, please provide its contents. – the busybee Sep 12 '19 at 06:18
  • 2
    Possible duplicate of [How do I port this program from conio to curses?](https://stackoverflow.com/questions/12247674/how-do-i-port-this-program-from-conio-to-curses) – Thomas Dickey Sep 12 '19 at 07:42
  • 1
    Possible duplicate of [Why can't I find on Linux?](https://stackoverflow.com/questions/8792317/why-cant-i-find-conio-h-on-linux) – Tsyvarev Sep 12 '19 at 10:25

0 Answers0