Sublime Forum

Problem to include curses.h library

#1

Hi guys,
i’m a newbie in programming and working with sublimetext3.
I got my first lesson’s in my school about the language “C”.
My problem is, that i get some errors, if i try to include the curses.h library.
I already installed the libncurses5-dev packages, but i don’t know whats gwan.

Here is my script:

#include <stdio.h>
#include <curses.h>

int main()
{
    char CodeByte;
    printf("Bitte betaetigen Sie die Funktionstaste F7 !\n\n");
    CodeByte = getch();
    printf("1. Tastencode-Byte: %2d\n",CodeByte);
    CodeByte = getch();
    printf("2. Tastencode-Byte: %2d\n",CodeByte);
    getch();
    return 0;
}

Here my Log:

/tmp/ccPdiLDF.o: In function main': cursestest.c:(.text+0x15): undefined reference tostdscr’
cursestest.c:(.text+0x1d): undefined reference to wgetch' cursestest.c:(.text+0x3c): undefined reference tostdscr’
cursestest.c:(.text+0x44): undefined reference to wgetch' cursestest.c:(.text+0x63): undefined reference tostdscr’
cursestest.c:(.text+0x6b): undefined reference to `wgetch’
collect2: error: ld returned 1 exit status
[Finished in 0.1s with exit code 1]
[cmd: [‘g++’, ‘/media/oem/Daten/Dokumente/C/cursestest.c’, ‘-o’, ‘/media/oem/Daten/Dokumente/C/cursestest’]]
[dir: /media/oem/Daten/Dokumente/C]
[path: /home/oem/bin:/home/oem/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]

BTW: I’m from Germany so forgive my grammar misstakes. I hope you can help me. It’s would be nice to get the answers, so easy as possible. Cause my technical know is not the best. Thanks :slightly_smiling:
I’m using OS Linuxmint 18.1

0 Likes

#2

What you’re seeing is a link error.

This is your compilation command:

g++ /media/oem/Daten/Dokumente/C/cursestest.c -o /media/oem/Daten/Dokumente/C/cursestest

It doesn’t link with the ncurses library anywhere. It’s probably installed in a default path somewhere, so try this:

g++ /media/oem/Daten/Dokumente/C/cursestest.c -lncurses -o /media/oem/Daten/Dokumente/C/cursestest
1 Like

#3

Perfect i write dis inna terminal and it’s works now :smiley:
If i create a new file, i have the same problem. Where can i change the compilation command in sublimetext?

0 Likes

#4

You’re probably using one of Sublime’s pre-packaged build system (Tools -> Build System). Those almost never work for me. What I like to do is write my .sublime-project file, and write my custom build system in there. Every non-trivial C and C++ project has a custom build system. Here is something to get you started:

{
  "build_systems":
  [
    {
      "file_regex": "(.+[^:]):(\\d+):(\\d+): (?:fatal )?((?:error|warning): .+)$",
      "name": "cursestest",
      "shell_cmd": "g++ cursestest.c -lncurses -o cursestest",
      "working_dir": "${project_path}"
    }
  ],
  "folders":
  [
    {
      "path": "."
    }
  ],
  "settings":
  {
  }
}

Save this file as cursestest.sublime-project and put it inside the folder /media/oem/Daten/Dokumente/C. Open this file with Sublime, select your custom build system in Tools -> Build System (called cursestest) and press CTRL+B.

0 Likes

#5

i changed the line in my sublime-project and include the “-lncurses”, cause i already maked a own build. It works fine now.
Thank you very much for the fast support! You’re my savior :smiley:

1 Like