6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 10:20 pm

All times are UTC




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Mar 13, 2019 9:53 pm 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
I'm having a problem building a C program for the W65C265SXB board. I'm trying to build this C file:
Code:
#include <stdio.h>
void main() { puts("Hello, world"); }
First I compile it like this:
Code:
wdc816cc hello.c -ML
Then I need to turn it into a hex file to send it to the board over serial, which is the part I can't figure out. I'm trying to link it like this:
Code:
wdcln hello.obj
I've tried a bunch of different flags on the linker, and I always get "Undefined symbol: ~~puts" or something like that. The compiler manual says that puts is supported, and it's in the header file. I've also tried with the IDE and it seems to get the same error.

How do I invoke the linker?


Last edited by randrews on Thu Mar 14, 2019 1:03 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2019 11:24 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
I'm certainly no expert, but I remember having to provide a file to #include, e.g.
Code:
#include <stdio.h>

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Last edited by barrym95838 on Wed Mar 13, 2019 11:48 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2019 11:26 pm 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
Sorry, I did, forum formatting ate it. That would make it not compile anyway, it compiles fine, it won't link.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 12:21 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
randrews wrote:
Sorry, I did, forum formatting ate it.

Are you sure? I just tried it, and it worked fine. Everything between the [code] and [/code] gets displayed exactly as you write it. White space is preserved but formatting marks get ignored.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 1:05 am 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
Oh, you're right, it must be the WDC contact form that ate it. Before I posted it here I asked the same thing in an email to WDC (since it's their compiler) and copied it out of the acknowledgement it sent me.

Anyway I just edited it to put the stdio.h bit in there. It compiles without a problem, and the resulting asm (if you pass -a) has an external reference to puts. But the linker can't find it no matter what I tell it to link against.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 10:13 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 336
According to the documentation, you need -LC in the linker command line, and the location of the directory containing the standard libraries in the environment variable WDC_LIB. The example directory they give is C:\WDC\LIB, but it's going to depend on where the compiler got installed on your computer.

Compiler docs http://www.westerndesigncenter.com/wdc/documentation/W65C02_C_Compiler.pdf page 40
Linker docs http://www.westerndesigncenter.com/wdc/documentation/Assembler_Linker.pdf page 33

I've never tried using the WDC compiler, so I don't know whether that will actually work. But hopefully there's enough in the documentation to get you there.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 11:38 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
The WDC library may not contain implementations for the stdio functions as they are very hardware dependent.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 1:34 pm 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
Adding -LC doesn't help (or -L anything else for that matter, none of the stuff in lib seems to contain the C standard library).

The manual says it does contain the stdio functions, but even if it doesn't, other functions (atoi is the one I tried) aren't there either, so it's not able to link in any libraries.

WDC_LIB is set, to the directory holding all the .obj files that it installed.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 4:39 pm 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Is there any file in the installation with a name matching libc or LIBC or any combination?


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 5:35 pm 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
Sure, tons:

c0.obj, c0c.obj, c0l.obj, c0m.obj, c0s.obj, c134.lib, c.lib, cc.lib, cl.lib, cm.lib, cs.lib, m134.lib, m.lib, mc.lib, ml.lib, mm.lib, ms.lib.

If I pass it -lcl and try to link against c0l.obj (which is what TIDE tries to do) it also says it can't find a bunch of other stuff, like close, write, IRQhandler, etc.

I'm sure the answer is that I'm not linking in the correct combination of these files but I can't find in the manual anywhere which ones I need. I would be willing to deal with it if the non-stdio stuff worked (having a puts that writes to the monitor would be a nice bonus but I wasn't really expecting it), but without the rest of the standard library, I mean, the compiler is kind of useless, even if it does technically compile things. I'd have to reimplement all that stuff on my own to use it.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 5:41 pm 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
Although to be fair it does compile and link things that don't use the standard library. As long as I'm willing to reimplement all that stuff myself (or find an open source one) I can use it.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 6:17 pm 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
I think I might have figured this out, no thanks to the manual: wdclib -s shows me that all the C library functions are in the whatever.lib files, and if I add those to the linker then it finds them and complains that some other things are missing: __unlink, __close, __isatty, __write, __lseek. But it only needs those symbols if I use anything in stdio. So maybe those are things I need to implement myself in order to use stdio functions? But non-stdio stuff will link now, at least, which is good enough, because I can make inline asm functions to write strings to the monitor.

So the final answer seems to be:
Code:
wdc816cc your_file.c -ML
wdcln your_file.obj cl.lib

(or with whatever memory model you want, L is the slowest but largest one)


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 6:31 pm 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
ah, memory models, just to make life a little more complicated! Unavoidable, though, I think, for an '816.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 6:40 pm 
Offline

Joined: Wed Mar 13, 2019 9:41 pm
Posts: 20
The memory model thing is probably why you have to manually tell it what to link against. There are five copies of the std lib, one for each memory model and (I guess?) one for the 6502.

And it makes sense that fcntl.h would have no implementation, it would just be nice if the manual would TELL you that, or if they had an example C project, or if TIDE actually worked out of the box, or.... Yeah.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2019 10:52 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
randrews wrote:
I think I might have figured this out, no thanks to the manual: wdclib -s shows me that all the C library functions are in the whatever.lib files, and if I add those to the linker then it finds them and complains that some other things are missing: __unlink, __close, __isatty, __write, __lseek.

Yea, there shouldn't be any disk related code supplied.

I can name 2 '816 computers that had a disk drive: the Apple //GS, and the SuperCPU thing for the C64.

So, how CAN there be any disk support code with the compiler. For what machines? It would be nice if there was sample code that could be used and ported, however.

stdio can exist, simply because it can work with a serial console, but even then I'd be surprised if there was any real support.

At best, they should have libraries that leverage the monitors built in to the W65C134SXB and W65C265SXB boards.

Otherwise, yea, you get to write the rest yourself.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 31 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: