OSX:Clang / Ld说,即使存在并且所有参数都是正确的,它也可以找到静态库

发布于 2025-02-09 14:21:23 字数 708 浏览 1 评论 0原文

我知道这将是一个愚蠢的错误,而且我知道帖子有类似的帖子,但是到目前为止没有任何帮助,所以我正在求助于新帖子。

我正在尝试编译最简单的GLFW Hello World示例。

在我的项目目录(我正在使用vscode)中,有一个main.cpp文件,以及我从glfw.org下载的glfw lib文件,我将其重命名为libglfw3.a(已预编译)我正在使用MacBook Air M1。

我正在尝试使用此命令进行编译:

clang -i/opt/homebrew/cellar/glfw/3.3.7/include -l/users // projects/-l libglfw3.a main.cpp -o helloglfw

输出i GET IS:

LD:未找到-llibglfw3.a的库 clang:错误:链接器命令因出口代码1失败(使用-v查看调用)

我显然很愚蠢,因为我一生看不到我在做错什么...

我尝试过的事情:

  1. 链接到GLFW的Homebrew版本,该版本包含一个.dylib Glfw
  2. 尝试链接libglfw3(无需.A扩展名)
  3. 将编译到对象文件,然后
  4. 使用g ++
  5. 分别使用g ++链接到ld,而不是使用-l flag并将完整路径粘贴到-l
  6. 祈祷和重新启动PC,以防万一。
  7. 等待它修复

一些帮助将不胜感激。

I know it's going to be a silly mistake, and I'm aware that there are similar posts however none have helped so far, so I'm resorting to a new post.

I'm trying to compile the simplest GLFW hello world example.

In my project directory (I'm using vscode) there is a main.cpp file, and the glfw lib file I downloaded from glfw.org which I renamed to libglfw3.a (It's precompiled) I am using a MacBook Air M1.

I'm trying to compile it with this command:

clang -I /opt/homebrew/Cellar/glfw/3.3.7/include -L /Users//projects/ -l libglfw3.a main.cpp -o helloglfw

The output I get is:

ld: library not found for -llibglfw3.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm clearly dumb because for the life of me I can't see what I'm doing wrong...

Things I've tried:

  1. linking to the homebrew version of glfw which contains a .dylib of glfw
  2. tried linking libglfw3 (without the .a extension)
  3. compiling to an object file and then linking with ld separately
  4. using g++
  5. Not using the -L flag and just pasting the full path into -l
  6. Praying and restarting the pc just in case.
  7. Waiting for it to fix itself

Some assistance would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉徒眸意 2025-02-16 14:21:23

好吧!我修复了它。显然,如果-L和-L参数之间没有空间,则可以工作。

所以命令看起来像这样:

clang <source files> -I<Include Paths> -L<pathtolibs>-l<libs>

不知道为什么,但是我做的一切...

OK SO! I fixed it. Apparently it works if there is NO SPACE between the -L and -l parameters.

so the command looks like this:

clang <source files> -I<Include Paths> -L<pathtolibs>-l<libs>

No clue why, but whatever I'm done...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文