Yang_Yang
(Yang Yang)
December 30, 2016, 7:17pm
1
I try to wrap a c library in swift package named Test.
The code looks like this:
Test1.h
struct MyParams {
int (*func)();
};
typedef struct MyParams MyParams;
Test2.h
#include "Test1.h"
static int test(){
return 0;
}
void myTest()
{
MyParams params;
params.func = test;
}
Then I try to import the package into swift code and use
in Test.swift.
···
************************
import Test
class TestSwift {
func runtest(){
myTest()
}
}
However, the compiler report link error:
function myTest: error: undefined reference to 'test'
If I comment out
"params.func = test;" in myTest.
It successfully build. How should I handle this situation?
Thanks,
Yang
Can you create a quick tarball of the swiftpm project. Would expedite the answering of the question.
Michael
···
On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users <swift-users@swift.org> wrote:
I try to wrap a c library in swift package named Test.
The code looks like this:
Test1.h
struct MyParams {
int (*func)();
};
typedef struct MyParams MyParams;
Test2.h
#include "Test1.h"
static int test(){
return 0;
}
void myTest()
{
MyParams params;
params.func = test;
}
Then I try to import the package into swift code and use
in Test.swift.
************************
import Test
class TestSwift {
func runtest(){
myTest()
}
}
However, the compiler report link error:
function myTest: error: undefined reference to 'test'
If I comment out
"params.func = test;" in myTest.
It successfully build. How should I handle this situation?
Thanks,
Yang
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
Joe_Groff
(Joe Groff)
January 4, 2017, 6:29pm
3
Try making `test` static inline instead of just static.
-Joe
···
On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users <swift-users@swift.org> wrote:
I try to wrap a c library in swift package named Test.
The code looks like this:
Test1.h
struct MyParams {
int (*func)();
};
typedef struct MyParams MyParams;
Test2.h
#include "Test1.h"
static int test(){
return 0;
}
void myTest()
{
MyParams params;
params.func = test;
}
Then I try to import the package into swift code and use
in Test.swift.
************************
import Test
class TestSwift {
func runtest(){
myTest()
}
}
However, the compiler report link error:
function myTest: error: undefined reference to 'test'
If I comment out
"params.func = test;" in myTest.
It successfully build. How should I handle this situation?
Yang_Yang
(Yang Yang)
January 4, 2017, 4:44am
4
Hi Michael,
The attachment is the packages I created for testing purpose.
You can check it.
Thanks for the help,
Yang
Test1.tar.gz (91.1 KB)
···
2016-12-30 18:15 GMT-06:00 Michael Gottesman <mgottesman@apple.com>:
Can you create a quick tarball of the swiftpm project. Would expedite the
answering of the question.
Michael
> On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users < > swift-users@swift.org> wrote:
>
> I try to wrap a c library in swift package named Test.
> The code looks like this:
>
> Test1.h
>
> struct MyParams {
> int (*func)();
> };
>
> typedef struct MyParams MyParams;
>
> Test2.h
> #include "Test1.h"
>
> static int test(){
> return 0;
> }
>
> void myTest()
> {
> MyParams params;
> params.func = test;
> }
>
>
> Then I try to import the package into swift code and use
> in Test.swift.
> ************************
> import Test
>
> class TestSwift {
> func runtest(){
> myTest()
> }
> }
>
> However, the compiler report link error:
> function myTest: error: undefined reference to 'test'
>
> If I comment out
> "params.func = test;" in myTest.
>
> It successfully build. How should I handle this situation?
>
> Thanks,
>
> Yang
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
Yang_Yang
(Yang Yang)
January 5, 2017, 5:20am
5
Thanks.
It compiled successfully now under linux.
···
2017-01-04 12:29 GMT-06:00 Joe Groff <jgroff@apple.com>:
> On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users < > swift-users@swift.org> wrote:
>
> I try to wrap a c library in swift package named Test.
> The code looks like this:
>
> Test1.h
>
> struct MyParams {
> int (*func)();
> };
>
> typedef struct MyParams MyParams;
>
> Test2.h
> #include "Test1.h"
>
> static int test(){
> return 0;
> }
>
> void myTest()
> {
> MyParams params;
> params.func = test;
> }
>
>
> Then I try to import the package into swift code and use
> in Test.swift.
> ************************
> import Test
>
> class TestSwift {
> func runtest(){
> myTest()
> }
> }
>
> However, the compiler report link error:
> function myTest: error: undefined reference to 'test'
>
> If I comment out
> "params.func = test;" in myTest.
>
> It successfully build. How should I handle this situation?
Try making `test` static inline instead of just static.
-Joe
Yang_Yang
(Yang Yang)
January 5, 2017, 4:29pm
6
sorry, i made mistake on compiling. It still report the same link error.
Yang
···
On Wed, Jan 4, 2017 at 11:20 PM Yang Yang <cometyang@gmail.com> wrote:
Thanks.
It compiled successfully now under linux.
2017-01-04 12:29 GMT-06:00 Joe Groff <jgroff@apple.com>:
> On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users < > swift-users@swift.org> wrote:
>
> I try to wrap a c library in swift package named Test.
> The code looks like this:
>
> Test1.h
>
> struct MyParams {
> int (*func)();
> };
>
> typedef struct MyParams MyParams;
>
> Test2.h
> #include "Test1.h"
>
> static int test(){
> return 0;
> }
>
> void myTest()
> {
> MyParams params;
> params.func = test;
> }
>
>
> Then I try to import the package into swift code and use
> in Test.swift.
> ************************
> import Test
>
> class TestSwift {
> func runtest(){
> myTest()
> }
> }
>
> However, the compiler report link error:
> function myTest: error: undefined reference to 'test'
>
> If I comment out
> "params.func = test;" in myTest.
>
> It successfully build. How should I handle this situation?
Try making `test` static inline instead of just static.
-Joe
I simplified your example package and posted a bug report here:
opened 05:33PM - 05 Jan 17 UTC
bug
compiler
| | |
|------------------|-----------------|…
|Previous ID | SR-3556 |
|Radar | None |
|Original Reporter | @aciidb0mb3r |
|Type | Bug |
Attachment: [Download](https://user-images.githubusercontent.com/2727770/164961817-ddaca97f-8e04-4836-b0b6-408d04121707.gz)
<details>
<summary>Additional Detail from JIRA</summary>
| | |
|------------------|-----------------|
|Votes | 0 |
|Component/s | Compiler |
|Labels | Bug, ClangImporter |
|Assignee | None |
|Priority | Medium |
md5: d37609c53cd5612a31aa1e5b9ec6fa8a
</details>
**Issue Description:**
Attached package doesn't build with swift package manager because the C module has a method defined in the header instead of the .c file:
``` java
Compile Swift Module 'exe' (1 sources)
Linking ./.build/debug/exe
Undefined symbols for architecture x86_64:
"_test", referenced from:
_myTest in main.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Users/ankit/workspace/swift.org/swiftpm/.build/debug/swift-build-tool -f /Users/ankit/Downloads/Test1/.build/debug.yaml
```
···
On Thu, Jan 5, 2017 at 9:59 PM, Yang Yang via swift-users < swift-users@swift.org> wrote:
sorry, i made mistake on compiling. It still report the same link error.
Yang
On Wed, Jan 4, 2017 at 11:20 PM Yang Yang <cometyang@gmail.com> wrote:
Thanks.
It compiled successfully now under linux.
2017-01-04 12:29 GMT-06:00 Joe Groff <jgroff@apple.com>:
> On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users < >> swift-users@swift.org> wrote:
>
> I try to wrap a c library in swift package named Test.
> The code looks like this:
>
> Test1.h
>
> struct MyParams {
> int (*func)();
> };
>
> typedef struct MyParams MyParams;
>
> Test2.h
> #include "Test1.h"
>
> static int test(){
> return 0;
> }
>
> void myTest()
> {
> MyParams params;
> params.func = test;
> }
>
>
> Then I try to import the package into swift code and use
> in Test.swift.
> ************************
> import Test
>
> class TestSwift {
> func runtest(){
> myTest()
> }
> }
>
> However, the compiler report link error:
> function myTest: error: undefined reference to 'test'
>
> If I comment out
> "params.func = test;" in myTest.
>
> It successfully build. How should I handle this situation?
Try making `test` static inline instead of just static.
-Joe
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
--
Ankit