提问人:pizzalawl 提问时间:8/21/2023 更新时间:8/21/2023 访问量:62
链接器没有检测到我为 raylib 制作的静态库
Linker doesn't detect my static library made for raylib
问:
我目前正在尝试创建一个小型库来在 raylib 中制作对话框。但是,当我尝试使用我的 Makefile 时,我收到此错误。请注意,我对 c++ 有点陌生!
/sbin/ld: cannot find -ldialog: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:14: test] Error 1
这是我的其余代码,因为我不确定是什么原因导致的,因为头文件和库文件分别位于 /usr/include 和 /usr/lib 中。
对话框.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
测试.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;
}
生成文件:
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
先谢谢你!
答: 暂无答案
评论
-L.
$(LIBS)
-c
.o
make
test
libdialog.a
libdialog.a
test
main': test.cpp:(.text+0x59): undefined reference to
libdialog.a
-static
-ldialog
dialog.h
void DialogueBox::draw() { ... }