I am currently trying to create a tiny library to make dialog boxes in raylib. When I try to use my Makefile, though, I get this error. Please note that I'm a bit new to c++!:
/sbin/ld: cannot find -ldialog: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:14: test] Error 1
Here's the rest of my code as I am seriously not sure what could be causing it as the header and library files are both in /usr/include and /usr/lib respectively.
dialog.cpp -
#include <cstring>
#include <string>
#include <raylib.h>
using namespace std;
class DialogueBox {
public:
float thickness;
Color box_background;
char *contents;
bool shadow;
Rectangle rectangle;
DialogueBox(float x, float y, float width, float height) {
Rectangle rectangle = {x,y,width,height};
contents = "Hello!";
}
void Draw(){
if(shadow){
DrawRectangle(rectangle.x + 10,rectangle.y + 10,rectangle.width,rectangle.height,GRAY);
}
DrawRectangleRec(rectangle, box_background);
DrawRectangleLinesEx(rectangle, thickness, BLACK);
for(int i = 0; i < strlen(contents); i++){
char charBuffer[2] = {contents[i], '\0'};
DrawText(std::string(1, contents[i]).c_str(), rectangle.x, rectangle.y, 5, BLACK);
}
}
};
dialog.h:
#ifndef DIALOGUE_BOX_H
#define DIALOGUE_BOX_H
#include <cstring>
#include <string>
#include <raylib.h>
class DialogueBox {
public:
DialogueBox(float x, float y, float width, float height);
void Draw();
float thickness;
Color box_background;
char *contents;
bool shadow;
Rectangle rectangle;
};
#endif // DIALOGUE_BOX_H
test.cpp:
#include "dialog.h"
#include "raylib.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
DialogueBox dialog(5, screenHeight/4, screenHeight/4 + screenHeight/4, screenWidth - 5);
dialog.thickness = 5;
dialog.box_background = GRAY;
dialog.shadow = true;
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
dialog.Draw();
EndDrawing();
}
CloseWindow();
return 0;
}
Makefile:
CC = gcc
CFLAGS = -O1
LIBS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
all: dialog.o libdialog.a install test
dialog.o: dialog.cpp
$(CC) $(CFLAGS) -c dialog.cpp -o dialog.o $(LIBS)
libdialog.a: dialog.o
ar rcs libdialog.a dialog.o
rm dialog.o
test: test.cpp
$(CC) $(CFLAGS) test.cpp -o test $(LIBS) -ldialog
clean:
rm /usr/bin/libdialog.a
rm /usr/include/dialog.h
rm libdialog.a
install: libdialog.a dialog.h
cp libdialog.a /usr/bin
cp dialog.h /usr/include
Thank you in advance!