opengl 链接Bazel中现有的c++静态库失败

guykilcj  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(210)

我正在Windows上写一个OpenGL程序。
我想链接预编译的GLEW32.lib,但是失败了,失败了几个小时。
在WORKSPACE中,http_archive使用下载GLEW32.lib

http_archive(
  name = "glew",
  build_file = "@//:thirdparty/glew.BUILD",
  sha256 = "ea6b14a1c6c968d0034e61ff6cb242cff2ce0ede79267a0f2b47b1b0b652c164",
  strip_prefix = "glew-2.2.0",
  urls = ["https://github.com/nigels-com/glew/releases/download/glew-2.2.0/glew-2.2.0-win32.zip"],
)

GLEW.构建如下

package(default_visibility=["//visibility:public"])
load("@rules_cc//cc:defs.bzl", "cc_binary")

cc_import(
  name = "glew_lib",
  static_library = "lib/Release/x64/glew32s.lib",
  hdrs = glob([
    "include/GL/*.h"
  ]),
)

cc_library(
  name = "glew"
  includes = ["include"],
  deps = ["glew_lib"]
)

依赖二进制如下

cc_binary(
  name = "window",
  srcs = [
    "window.cc",
  ],
  deps = [
    "//engine:debug",
    "//engine:gl",
    "//playground:playground",
    "@fmt",
    "@glew",
    "@glfw",
    "@glm",
    "@imgui",
  ],
  linkstatic = 1
)

链接参数文件C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\link.exe @bazel-out/x64_windows-fastbuild/bin/playground/window.exe-2.params的GLEW库很奇怪。我不知道external/glew/lib/Release/x64/glew32s.lib是怎么生成的。但是GLEW.lib没有join链接。

/nologo
/OUT:bazel-out/x64_windows-fastbuild/bin/playground/window.exe
bazel-out/x64_windows-fastbuild/bin/playground/_objs/window/window.obj
bazel-out/x64_windows-fastbuild/bin/playground/playground.lib
bazel-out/x64_windows-fastbuild/bin/playground/scene/scenes.lib
bazel-out/x64_windows-fastbuild/bin/playground/pass.lib
bazel-out/x64_windows-fastbuild/bin/playground/object/object.lib
bazel-out/x64_windows-fastbuild/bin/engine/framebuffer/framebuffer.lib
bazel-out/x64_windows-fastbuild/bin/playground/context.lib
bazel-out/x64_windows-fastbuild/bin/engine/repo/repo.lib
bazel-out/x64_windows-fastbuild/bin/engine/engine.lib
bazel-out/x64_windows-fastbuild/bin/engine/primitive/primitive.lib
bazel-out/x64_windows-fastbuild/bin/engine/mesh.lib
bazel-out/x64_windows-fastbuild/bin/engine/gl.lib
bazel-out/x64_windows-fastbuild/bin/external/assimp/assimp.lib
bazel-out/x64_windows-fastbuild/bin/engine/util.lib
bazel-out/x64_windows-fastbuild/bin/engine/proto/config_proto.lib
bazel-out/x64_windows-fastbuild/bin/external/com_github_protocolbuffers_protobuf/protobuf.lib
bazel-out/x64_windows-fastbuild/bin/external/com_github_protocolbuffers_protobuf/protobuf_lite.lib
bazel-out/x64_windows-fastbuild/bin/external/com_github_google_glog/glog.lib
bazel-out/x64_windows-fastbuild/bin/external/com_github_gflags_gflags/gflags.lib
bazel-out/x64_windows-fastbuild/bin/external/fmt/fmt.lib
external/glew/lib/Release/x64/glew32s.lib
bazel-out/x64_windows-fastbuild/bin/external/imgui/imgui.lib
bazel-out/x64_windows-fastbuild/bin/external/glfw/glfw_src.lib
/SUBSYSTEM:CONSOLE
-ignore:4221
-ignore:4221
-DEFAULTLIB:user32.lib
-DEFAULTLIB:gdi32.lib
-DEFAULTLIB:shell32.lib
/MACHINE:X64
/DEFAULTLIB:msvcrt.lib
/DEBUG:FASTLINK
/INCREMENTAL:NO

有人能帮我链接到已经存在的GLEW32.lib成功吗?非常感谢。

bksxznpy

bksxznpy1#

我的错。这不是bazel的问题,也不是glew的问题。GLEW的意思是OpenGL扩展管理员库。它不包含原始OpenGL函数实现。
在将linkopts = ["-DEFAULTLIB:opengl32.lib"]添加到glew cc_library之后,每一个都可以。
链接错误如下。它们都是原始的OpenGL函数。

gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glBindTexture referenced in function "void __cdecl glBindTexture_(unsigned int,unsigned int)" (?glBindTexture_@@YAXII@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glClear referenced in function "void __cdecl glClear_(unsigned int)" (?glClear_@@YAXI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glClearColor referenced in function "void __cdecl
glClearColor_(float,float,float,float)" (?glClearColor_@@YAXMMMM@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glCullFace referenced in function "void __cdecl glCullFace_(unsigned int)" (?glCullFace_@@YAXI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glDeleteTextures referenced in function "void __cdecl glDeleteTextures_(int,unsigned int const *)" (?glDeleteTextures_@@YAXHPEBI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glDisable referenced in function "void __cdecl glDisable_(unsigned int)" (?glDisable_@@YAXI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glDrawArrays referenced in function "void __cdecl
glDrawArrays_(unsigned int,int,int)" (?glDrawArrays_@@YAXIHH@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glDrawBuffer referenced in function "void __cdecl
glDrawBuffer_(unsigned int)" (?glDrawBuffer_@@YAXI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glDrawElements referenced in function "void __cdecl glDrawElements_(unsigned int,int,unsigned int,void const *)" (?glDrawElements_@@YAXIHIPEBX@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glEnable referenced in function "void __cdecl glEnable_(unsigned int)" (?glEnable_@@YAXI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glFrontFace referenced in function "void __cdecl glFrontFace_(unsigned int)" (?glFrontFace_@@YAXI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGenTextures referenced in function "void __cdecl glGenTextures_(int,unsigned int *)" (?glGenTextures_@@YAXHPEAI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGetBooleanv referenced in function "void __cdecl glGetBooleanv_(unsigned int,unsigned char *)" (?glGetBooleanv_@@YAXIPEAE@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGetDoublev referenced in function "void __cdecl
glGetDoublev_(unsigned int,double *)" (?glGetDoublev_@@YAXIPEAN@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGetError referenced in function "unsigned int __cdecl glewInit_(void)" (?glewInit_@@YAIXZ)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGetFloatv referenced in function "void __cdecl glGetFloatv_(unsigned int,float *)" (?glGetFloatv_@@YAXIPEAM@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGetIntegerv referenced in function "void __cdecl glGetIntegerv_(unsigned int,int *)" (?glGetIntegerv_@@YAXIPEAH@Z)
glew.lib(glew.obj) : error LNK2001: unresolved external symbol __imp_glGetIntegerv
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGetTexImage referenced in function "void __cdecl glGetTexImage_(unsigned int,int,unsigned int,unsigned int,void *)" (?glGetTexImage_@@YAXIHIIPEAX@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glGetTexLevelParameteriv referenced in function "void __cdecl glGetTexLevelParameteriv_(unsigned int,int,unsigned int,int *)" (?glGetTexLevelParameteriv_@@YAXIHIPEAH@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glReadBuffer referenced in function "void __cdecl
glReadBuffer_(unsigned int)" (?glReadBuffer_@@YAXI@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glTexImage2D referenced in function "void __cdecl
glTexImage2D_(unsigned int,int,int,int,int,int,unsigned int,unsigned int,void const *)" (?glTexImage2D_@@YAXIHHHHHIIPEBX@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glTexParameteri referenced in function "void __cdecl glTexParameteri_(unsigned int,unsigned int,int)" (?glTexParameteri_@@YAXIIH@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glTexSubImage2D referenced in function "void __cdecl glTexSubImage2D_(unsigned int,int,int,int,int,int,unsigned int,unsigned int,void const *)" (?glTexSubImage2D_@@YAXIHHHHHIIPEBX@Z)
gl.lib(gl.obj) : error LNK2019: unresolved external symbol __imp_glViewport referenced in function "void __cdecl glViewport_(int,int,int,int)" (?glViewport_@@YAXHHHH@Z)

相关问题