Search code examples
c++raylib

Why I can't use external library ray lib?


I was trying to use external library ncurses, however I did not found throughout tutorials and tried the same with ray lib, but it doesn't work too(((. When my task.json is like this this error appears:

{
    "tasks": [
      {
        "type": "cppbuild",
        "label": "C/C++: clang++ build active file",
        "command": "/Library/Developer/CommandLineTools/usr/bin/clang++",
        "args": [
          "-fcolor-diagnostics",
          "-fansi-escape-codes",
          "-g",
          "${file}",
          "-o",
          "${fileDirname}/${fileBasenameNoExtension}",
          "-lraylib",
          "/opt/homebrew/cellar/raylib/5.0/include"
        ],
        "options": {
          "cwd": "${fileDirname}"
        },
        "problemMatcher": ["$gcc"],
        "group": {
          "kind": "build",
          "isDefault": true
        },
        "detail": "Task generated by Debugger."
      }
    ],
    "version": "2.0.0"
}
/Users/username/tutorial/main.cpp:24:10: fatal error: 'raylib.h' file not found
#include <raylib.h>
         ^~~~~~~~~~
1 error generated.

Сборка завершена с ошибками.

 *  The terminal process failed to launch (exit code: -1). 
 *  Terminal will be reused by tasks, press any key to close it.

But when it is like this: (I changed only this parts so I am showing only them)

        "command": "/opt/homebrew/cellar/raylib/5.0/include",
        "args": [
          "-fcolor-diagnostics",
          "-fansi-escape-codes",
          "-g",
          "${file}",
          "-o",
          "${fileDirname}/${fileBasenameNoExtension}",
          "-lraylib"
        ],

This error appears:

/Library/Developer/CommandLineTools/usr/bin -fcolor-diagnostics -fansi-escape-codes -g /Users/username/tutorial/main.cpp -o /Users/username/tutorial/main -lraylib
/bin/sh: /Library/Developer/CommandLineTools/usr/bin: is a directory

Сборка завершена с ошибками.

 *  The terminal process failed to launch (exit code: -1). 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: C/C++: clang++ build active file 

I am changing the command line by the way. Helps pls.


Solution

  • Probably like this

    "args": [
          "-fcolor-diagnostics",
          "-fansi-escape-codes",
          "-g",
          "-I/opt/homebrew/cellar/raylib/5.0/include"
          "${file}",
          "-o",
          "${fileDirname}/${fileBasenameNoExtension}",
          "-L/opt/homebrew/cellar/raylib/5.0/lib"
          "-lraylib",
        ],
    

    Use -I to say where the header files are located, use -L to say where the library files are located (here I guessing that they are in /opt/homebrew/cellar/raylib/5.0/lib), library options should go at the end.

    If you are going to build using tasks.json it's important that you understand the different options you can give to g++.