GCC在构建时未定义的引用

I am trying to build an exe for windows amd64 using golang. Everything is running smoothly except on "go run" or "go build". The build process is breaking on gcc compile of the package from github.com/andlabs/ui. The trace goes as follows:

$ go build
# gitlab.com/asnossascenas/dbRegistration/ui
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiNewTable':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:66: undefined reference to `uiNewTable'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiNewTableModel':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:83: undefined reference to `uiNewTableModel'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableAppendTextColumn':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:103: undefined reference to `uiTableAppendTextColumn'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableGetSelection':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:120: undefined reference to `uiTableGetSelection'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableIterAdvance':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:138: undefined reference to `uiTableIterAdvance'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableIterCurrent':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:168: undefined reference to `uiTableIterCurrent'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `realuiTableOnSelectionChanged':
C:/GoPath/src/gitlab.com/asnossascenas/dbRegistration/ui/table.go:12: 
undefined reference to `uiTableOnSelectionChanged'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiFreeTableModel':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:49: undefined reference to `uiFreeTableModel'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableIterComplete':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:152: undefined reference to `uiTableIterComplete'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableModelRowChanged':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:184: undefined reference to `uiTableModelRowChanged'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableModelRowDeleted':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:198: undefined reference to `uiTableModelRowDeleted'
C:\Users\Pat\AppData\Local\Temp\go- 
build167765418\gitlab.com\asnossascenas\dbRegistration\ui\_obj\table.cgo2.o: 
In function `_cgo_1e2a701ee86d_Cfunc_uiTableModelRowInserted':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:212: undefined reference to `uiTableModelRowInserted'
C:\Users\Pat\AppData\Local\Temp\gobuild167765418\gitlab.com
\asnossascenas\dbRegistration\ui\_obj\tablemodelhandler.cgo2.o: In function 
`_cgo_1e2a701ee86d_Cfunc_uiTableModelStrdup':
/tmp/go-build\gitlab.com\asnossascenas\dbRegistration\ui\_obj/cgo-gcc- 
prolog:68: undefined reference to `uiTableModelStrdup'o `uiTableModelStrdup'                                                                                 
function `msgbox':
C:/GoPath/src/gitlab.com/asnossascenas/
dbRegistration/ui/libui_windows_amd64.a(stddialogs.cpp.obj): In function 
`msgbox':E:/github.com/andlabs/libui/windows/stddialogs.cpp:113: undefined 
reference to `__imp_TaskDialog'
collect2.exe: error: ld returned 1 exit status

I initially tried to crosscompile from linux to windows having roughly the same problem so I guess it's a matter of either the flags I should use to build it or maybe I am missing something dependency related...

I tried using CGO_ENABLED=1 and pretty much every other combination of flags possible on linux to crosscompile, sometimes triggering the error

gcc: error: unrecognized command line option ‘-mthreads’

eventually I decided I should move to Windows and compile natively, which doesn't seem to be working.

I am willing to provide any more information you might need to help me figure this out.

dongquexi1990
dongquexi1990 至少你让我笑了。是的,进口情况良好。我想并不是一切都顺利进行。
2 年多之前 回复
dopmgo4707
dopmgo4707 出于好奇,当您说“除了“运行”或“构建”外,一切都运行顺利”,那是什么“一切”?如果无法构建,该怎么办?就像去导入一样吗?
2 年多之前 回复

1个回答



根据 ui </ code>软件包的安装说明,您需要安装MingW 并设置一些环境变量以使其生成:</ p>

  set CGO_ENABLED = 1 
set CC = C: \ PROGRA〜1 \ mingw-w64 \ x86_64-7.2.0-win32-seh-rt_v5-rev1 \ mingw64 \ bin \ gcc.exe
set CXX = C:\ PROGRA〜1 \ mingw-w64 \ x86_64-7.2.0 -win32-seh-rt_v5-rev1 \ mingw64 \ bin \ g ++。exe
go build -ldflags -H = windowsgui
</ code> </ pre>
</ div>

展开原文

原文

According to the the installation instructions for the ui package you will need to install MingW and set some some environment variables to get it to build:

set CGO_ENABLED=1
set CC=C:\PROGRA~1\mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe
set CXX=C:\PROGRA~1\mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exe
go build -ldflags -H=windowsgui

dongnan1989
dongnan1989 遵循您的建议后,我仍然收到之前未定义的参考垃圾邮件。 这可能与GCC无法从库中读取正确的文件有关吗?
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问