vapor-community / mysql-provider

MySQL provider for the Vapor web framework.
MIT License
30 stars 12 forks source link

Swift build failed #16

Closed mengxiangyue closed 8 years ago

mengxiangyue commented 8 years ago

I use this in Package.json

.Package(url: "https://github.com/vapor/mysql-provider", majorVersion: 1),
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 0)

but i get a failure:

/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/mysql/bin/mysql.h' not found
    header "/usr/local/mysql/bin/mysql.h"
           ^
/Users/xiangyue/Desktop/vapor/Packages/MySQL-1.0.0/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^

And i already install mysql on my computer. How do i fix this? ths

loganwright commented 8 years ago

@mengxiangyue if you're using Vapor's toolbox, just vapor build will do the trick. If you're doing manually, you'll need to pass the correct build flags for the correct platform. Here's which ones we're using:

https://github.com/vapor/mysql/blob/master/vapor.json

mengxiangyue commented 8 years ago

@LoganWright ths The mysql's path is different, Now i have the error like below:

/Users/xiangyue/Desktop/vapor/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"

but now the path is

localhost:local xiangyue$ pwd
/usr/local
localhost:local xiangyue$ ls -al
total 24
drwxr-xr-x  16 xiangyue  wheel   544  9 20 11:51 .
drwxr-xr-x@ 10 root      wheel   340  9  7 12:34 ..
-rw-r--r--@  1 xiangyue  wheel  6148  9 20 11:54 .DS_Store
drwxr-xr-x  19 xiangyue  admin   646  9 20 09:41 Cellar
drwxr-xr-x   2 xiangyue  wheel    68  9 19 18:38 Frameworks
drwxr-xr-x  14 xiangyue  wheel   476  9 19 18:38 Homebrew
drwxrwxr-x  50 xiangyue  admin  1700  9 19 18:38 bin
drwxr-xr-x   4 xiangyue  admin   136  8  2 14:45 etc
drwxr-xr-x  15 xiangyue  admin   510  9 20 12:08 include
drwxr-xr-x  31 xiangyue  admin  1054  8  7 23:39 lib
lrwxr-xr-x   1 root      wheel    28  9 20 11:22 mysql -> mysql-5.7.15-osx10.11-x86_64
drwxr-xr-x  12 root      wheel   408  9 20 11:22 mysql-5.7.15-osx10.11-x86_64
drwxr-xr-x  19 xiangyue  admin   646  9 20 09:41 opt
drwxr-xr-x   2 xiangyue  wheel    68  9 19 18:38 sbin
drwxr-xr-x  16 xiangyue  admin   544  9 19 18:38 share
drwxr-xr-x   4 xiangyue  admin   136  9 19 18:38 var

I resolved this problem with this commond in include dir

ln -s /usr/local/mysql-5.7.15-osx10.11-x86_64/include/ ./mysql

But when i use vapor build still faiure:

Compile Swift Module 'TypeSafeRouting' (3 sources)
Compile Swift Module 'Vapor' (83 sources)
Compile Swift Module 'VaporMySQL' (1 sources)
Compile Swift Module 'App' (3 sources)
Linking ./.build/debug/App
ld: library not found for -lmysqlclient for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

I'm Chineses, not good at English. Ths!

helinyu commented 8 years ago

I meet this problem,too. How can I deal with it?

rmvz3 commented 8 years ago

Same here. I am starting to learn Vapor with your videos but I can't use MySQL

helinyu commented 8 years ago

I have fix this bug ,I use brew to install mysql , maybe while you install mysql with *.dmg file which may be not support x86 structure!! just like this:

brew install mysql brew link mysql

rmvz3 commented 8 years ago

It works! Thank you very much.

loganwright commented 8 years ago

Thanks for the help resolving this everyone. For those who get this in the future, the issue is passing appropriate linker flags. If you're using Toolbox then you won't need to do anything being vapor build. Otherwise, you'll need to include the flags specified here.

qi-shun-wang commented 8 years ago

I have use @helinyu 's method to solve this problem .Because I have already installed "MySQL.dmg",i just give terminate a cmd below : brew install mysql

And then rebuild again ,no error appear!

fedort commented 8 years ago

For anyone running into this issue on Linux make sure you have 'libmysqlclient-dev' installed.

For ubuntu:

apt-get install libmysqlclient-dev

eXhausted commented 7 years ago

@LoganWright

MacOS Sierra 10.12.1

MacBook-Pro:hello-sm username$ vapor build
Fetching Dependencies [Done]
Building Project [Failed]

Command:
build -Xswiftc -I/usr/local/include/mysql -Xlinker -L/usr/local/lib

Error (1):
<unknown>:0: error: build had 1 command failures
swift-build: error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/.build/debug.yaml

Output:
Linking CLibreSSL
Compile Swift Module 'TurnstileCrypto' (3 sources)
Compile Swift Module 'Jay' (21 sources)
Compile Swift Module 'SocksCore' (15 sources)
Compile Swift Module 'Polymorphic' (2 sources)
Compile Swift Module 'PathIndexable' (2 sources)
Compile Swift Module 'libc' (1 sources)
Compile Swift Module 'Core' (28 sources)
Compile Swift Module 'Node' (22 sources)
Compile Swift Module 'Socks' (5 sources)
Compile Swift Module 'Fluent' (35 sources)
Compile Swift Module 'Essentials' (2 sources)
Compile Swift Module 'TLS' (7 sources)
Compile Swift Module 'Console' (34 sources)
Compile Swift Module 'Leaf' (34 sources)
Compile Swift Module 'JSON' (8 sources)
Compile Swift Module 'Turnstile' (13 sources)
Compile Swift Module 'Random' (3 sources)
Compile Swift Module 'Cipher' (2 sources)
Compile Swift Module 'MySQL' (10 sources)
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/CMySQL-1.0.0/module.modulemap:14:12: error: header '/usr/local/include/mysql/mysql.h' not found
    header "/usr/local/include/mysql/mysql.h"
           ^
/Users/username/Documents/WorkProjects/ProjectName/src/ProjectName-Endpoint/hello-sm/Packages/MySQL-1.0.2/Sources/MySQL/Bind+Node.swift:8:12: error: could not build Objective-C module 'CMySQLMac'
    import CMySQLMac
           ^

Toolchain:
/usr/bin/swift

Help:
Join our Slack where hundreds of contributors
are waiting to help: http://vapor.team

Error: Build failed.
kvillaca commented 7 years ago

on Mac OS Sierra 10.12.2;

I am having the same issue as above.

thexande commented 7 years ago

I had the same issue with the posgresql connector. My solution is posted here: http://stackoverflow.com/questions/42171919/swift-vapor-postgres-xcode-build-error-could-not-build-objective-c-module-cpos/42171920#42171920

MoridinBG commented 7 years ago

If anybody still encounters this, try

brew install cmysql

I had this issue on OS X 10.12.4 with MySQL 5.7.18 from Homebrew and the latest Vapor Toolbox. vapor build --verbose actually notifies you about this:

note: you may be able to install cmysql using your system-packager:
brew install cmysql

This fixed it for me.

fenggeren commented 7 years ago

@MoridinBG
the first ths for this but I had installed cmysql, there is still buildtime errors.

/Users/huanao/Desktop/swift-server/Test/Vapor_Test0/.build/checkouts/cmysql.git-3946220544950307782/shim.h:4:10: 'mysql/mysql.h' file not found /Users/huanao/Desktop/swift-server/Test/Vapor_Test0/.build/checkouts/mysql.git-1890032512239690518/Sources/MySQL/Connection.swift:1:8: Could not build Objective-C module 'CMySQL'

vzsg commented 7 years ago

The cmysql homebrew package needs an update that hasn't been released yet. Until that moment, you have to:

  1. install cmysql (which you already did)
  2. open /usr/local/lib/pkgconfig/cmysql.pc for editing
  3. change the following line: includedir=${prefix}/include/mysql --> includedir=${prefix}/include.

Your project should build again.

fenggeren commented 7 years ago

@vzsg yes, edited the file. and it's build succeeded now. thanks.

tanner0101 commented 7 years ago

You should now be able to run brew upgrade cmysql. Version 2.0.2+ contains the fix.

eneko commented 7 years ago

I'm getting this error:

$ vapor build --verbose
Building Project ...
Linking ./.build/debug/App
ld: library not found for -lmysqlclient for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Here is my cmysql.pc file:

$ cat /usr/local/lib/pkgconfig/cmysql.pc
prefix=/usr/local/opt/mysql
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: MySQL
Description: MySQL client library
Version: 2.0
Cflags: -I${includedir}
Libs: -L${libdir} -lmysqlclient

Vapor:

 $ vapor --version
Vapor Toolbox: 2.0.3

Swift 4 (same error with Swift 3.1):

 $ swift --version
Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
Target: x86_64-apple-macosx10.9

I've tried updating all brew packages but error persists when running vapor build.

Error also appears when running swift build alone:

$ swift build
Linking ./.build/debug/App
ld: library not found for -lmysqlclient for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

However this works:

$ swift build -Xswiftc -I/usr/local/include/mysql -Xlinker -L/usr/local/lib
Compile Swift Module 'libc' (1 sources)
Compile Swift Module 'Polymorphic' (2 sources)
Compile Swift Module 'PathIndexable' (2 sources)
Compile Swift Module 'Jay' (21 sources)
Compile Swift Module 'Core' (29 sources)
Compile Swift Module 'Node' (22 sources)
Compile Swift Module 'JSON' (9 sources)
Compile Swift Module 'Console' (34 sources)
Compile Swift Module 'MySQL' (11 sources)
Compile Swift Module 'App' (31 sources)
Linking ./.build/debug/App