ошибка архитектуры при доступе к базе данных с использованием Golang - PullRequest
0 голосов
/ 27 марта 2020

Я использовал Golang и пытался соединить MySQL через следующие коды, которые также были учебными кодами, показанными в go -database \ sql. Однако я получил некоторые сообщения о том, что некоторые файлы не были созданы для архитектуры x86_64, а некоторые символы не были найдены для архитектуры x86_64.
Все коды редактировались в Goland (2019.3.4) на платформе macOS 10.15.4.

package main

import (
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
    "log"
)

func main() {
    db, err := sql.Open("mysql", "root:mmmm572011@tcp(127.0.0.1:3306)/bookstore")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()
}

Вот что я получил:

GOROOT=/usr/local/Cellar/go/1.14/libexec #gosetup
GOPATH=/Users/michaeltan/go #gosetup
/usr/local/Cellar/go/1.14/libexec/bin/go build -o /private/var/folders/tr/c6mwrj1928949n_6pnpj3mk40000gn/T/___go_build_main_go /Users/michaeltan/GolandProjects/test_sql/main.go #gosetup
# runtime/cgo
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd
Undefined symbols for architecture x86_64:
  "___stack_chk_fail", referenced from:
      _x_cgo_init in _x004.o
      __cgo_sys_thread_start in _x004.o
  "___stack_chk_guard", referenced from:
      _x_cgo_init in _x004.o
      __cgo_sys_thread_start in _x004.o
  "___stderrp", referenced from:
      __cgo_sys_thread_start in _x004.o
      _x_cgo_sys_thread_create in _x005.o
      _x_cgo_thread_start in _x008.o
  "_abort", referenced from:
      __cgo_sys_thread_start in _x004.o
      _x_cgo_sys_thread_create in _x005.o
      _x_cgo_thread_start in _x008.o
  "_fprintf", referenced from:
      __cgo_sys_thread_start in _x004.o
      _x_cgo_sys_thread_create in _x005.o
  "_free", referenced from:
      _threadentry in _x004.o
  "_fwrite", referenced from:
      _x_cgo_thread_start in _x008.o
  "_malloc", referenced from:
      _x_cgo_thread_start in _x008.o
  "_nanosleep", referenced from:
      _x_cgo_sys_thread_create in _x005.o
      __cgo_try_pthread_create in _x005.o
  "_pthread_attr_destroy", referenced from:
      _x_cgo_init in _x004.o
  "_pthread_attr_getstacksize", referenced from:
      _x_cgo_init in _x004.o
      __cgo_sys_thread_start in _x004.o
  "_pthread_attr_init", referenced from:
      _x_cgo_init in _x004.o
      __cgo_sys_thread_start in _x004.o
  "_pthread_cond_broadcast", referenced from:
      _x_cgo_notify_runtime_init_done in _x005.o
  "_pthread_cond_wait", referenced from:
      __cgo_wait_runtime_init_done in _x005.o
  "_pthread_create", referenced from:
      _x_cgo_sys_thread_create in _x005.o
      __cgo_try_pthread_create in _x005.o
     (maybe you meant: __cgo_try_pthread_create)
  "_pthread_detach", referenced from:
      _x_cgo_sys_thread_create in _x005.o
      __cgo_try_pthread_create in _x005.o
  "_pthread_mutex_lock", referenced from:
      __cgo_wait_runtime_init_done in _x005.o
      _x_cgo_notify_runtime_init_done in _x005.o
      _x_cgo_set_context_function in _x005.o
      __cgo_get_context_function in _x005.o
  "_pthread_mutex_unlock", referenced from:
      __cgo_wait_runtime_init_done in _x005.o
      _x_cgo_notify_runtime_init_done in _x005.o
      _x_cgo_set_context_function in _x005.o
      __cgo_get_context_function in _x005.o
  "_pthread_sigmask", referenced from:
      __cgo_sys_thread_start in _x004.o
  "_setenv", referenced from:
      _x_cgo_setenv in _x006.o
     (maybe you meant: _x_cgo_setenv)
  "_strerror", referenced from:
      __cgo_sys_thread_start in _x004.o
      _x_cgo_sys_thread_create in _x005.o
  "_unsetenv", referenced from:
      _x_cgo_unsetenv in _x006.o
     (maybe you meant: _x_cgo_unsetenv)
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

Compilation finished with exit code 2

Дополнительная информация: Golang (1.14 Darwin / amd64) устанавливается через Homebrew. Mysql устанавливается через Homebrew, а база данных в кодах уже создана в командах терминала.

Ответы [ 2 ]

0 голосов
/ 28 марта 2020

Я решил проблему после рассмотрения этой проблемы на GitHub. Все, что вам нужно сделать, это сделать комментарии настройки среды Conda в вашем .zshr c или .bash_profile.

0 голосов
/ 27 марта 2020

Вам действительно нужно установить Go через Brew? Я не доверяю этой установке. Я предпочитаю использовать официальную установку, чтобы избежать проблем. https://dl.google.com/go/go1.14.1.darwin-amd64.pkg

...