Discussion:
Newbie problem: linking fails
(too old to reply)
Götz Hoffart
2013-12-01 21:54:18 UTC
Permalink
Hi,

having worked a long time with Turbo C in the past, I'm having problems
with compiling and linking a simple C program, only some arithmetics and
a single prinf(). I'm using it on Debian GNU/Linux on a x86_64 machine.

Installation target is /opt/watcom, I invoke ". /opt/watcom/owsetenv.sh"
before compiling.

$ wcc386 -onatx -oh -ei -zp8 -6 -fp6 -bt=linux collatz.c
Open Watcom C32 Optimizing Compiler Version 1.9
[…]
collatz.c: 27 lines, included 712, 0 warnings, 0 errors
Code size: 67

-> all fine, I get 'collatz.o' as output. Good. Now I try to link it:

$ wlink FILE collatz.o FORMAT ELF NAME collatz
[…]
loading object files
searching libraries
Warning! W1008: cannot open clib3r.lib : No such file or directory
Warning! W1008: cannot open math387r.lib : No such file or directory
Warning! W1008: cannot open emu387.lib : No such file or directory
Error! E2028: printf_ is an undefined reference
Error! E2028: _cstart_ is an undefined reference
Warning! W1023: no starting address found, using 00000000
creating an ELF executable
file collatz.o(/home/goetz/src/collatz.c): undefined symbol printf_

Obviously watcom can't find the libraries. But owsetenv.sh should set
the right path environment, shouldn't it? What's wrong?

Thanks in advance,
Götz
Frank Beythien
2013-12-02 13:20:15 UTC
Permalink
Post by Götz Hoffart
Hi,
having worked a long time with Turbo C in the past, I'm having problems
with compiling and linking a simple C program, only some arithmetics and
a single prinf(). I'm using it on Debian GNU/Linux on a x86_64 machine.
Installation target is /opt/watcom, I invoke ". /opt/watcom/owsetenv.sh"
before compiling.
$ wcc386 -onatx -oh -ei -zp8 -6 -fp6 -bt=linux collatz.c
Open Watcom C32 Optimizing Compiler Version 1.9
[…]
collatz.c: 27 lines, included 712, 0 warnings, 0 errors
Code size: 67
$ wlink FILE collatz.o FORMAT ELF NAME collatz
[…]
loading object files
searching libraries
Warning! W1008: cannot open clib3r.lib : No such file or directory
Try to start with a simple

wcl386 -wx -'"option map"' collatz.c

and worry about optimization later.

The option map linker directive is to show you how to pass parms to
wlink via wcl.

CU
Frank
Götz Hoffart
2013-12-02 20:01:52 UTC
Permalink
Post by Frank Beythien
Try to start with a simple
wcl386 -wx -'"option map"' collatz.c
and worry about optimization later.
It may sound weird, but I had a hard time to find *simple* examples of
how commandline parameters work in the PDF manuals, and wcc386 --help or
-help didn't work either. That »optimization« line I found while
searching the web.

Regards
Götz
Paul S. Person
2013-12-03 18:07:22 UTC
Permalink
Post by Götz Hoffart
Post by Frank Beythien
Try to start with a simple
wcl386 -wx -'"option map"' collatz.c
and worry about optimization later.
It may sound weird, but I had a hard time to find *simple* examples of
how commandline parameters work in the PDF manuals, and wcc386 --help or
-help didn't work either. That »optimization« line I found while
searching the web.
It's not weird at all.

The documentation is and always has been written primarily for people
who already know what they are doing, and just need to be reminded of
a technical detail now and then.

To put it another way, the documentation of (say) wmake makes a /lot/
more sense if you already know how to write makefiles and just need a
few pointers on how OW makefiles work than if you have no idea at all
how to write a makefile.

But a lot of documentation, especially for compilers and similar tools
for professionals, is written that way.

The problem is intrinsic in any complex, technical topic: those that
have an interest in writing for newbies are so new themselves that
they lack the expertise required, and those who have the expertise are
no longer able to put themselves into the newbie's place and write a
manual for such a person.
--
"Nature must be explained in
her own terms through
the experience of our senses."
Frank Beythien
2013-12-03 20:13:23 UTC
Permalink
Post by Götz Hoffart
Post by Frank Beythien
Try to start with a simple
wcl386 -wx -'"option map"' collatz.c
and worry about optimization later.
It may sound weird, but I had a hard time to find *simple* examples of
how commandline parameters work in the PDF manuals, and wcc386 --help or
-help didn't work either. That »optimization« line I found while
searching the web.
Many of the OW tools give some help if called without any parms. Only
Wlink needs a ?, for linux protect it from shell expansion.

CU
Frank

Frank Beythien
2013-12-02 15:03:20 UTC
Permalink
Post by Götz Hoffart
Hi,
having worked a long time with Turbo C in the past, I'm having problems
with compiling and linking a simple C program, only some arithmetics and
a single prinf(). I'm using it on Debian GNU/Linux on a x86_64 machine.
Installation target is /opt/watcom, I invoke ". /opt/watcom/owsetenv.sh"
before compiling.
$ wcc386 -onatx -oh -ei -zp8 -6 -fp6 -bt=linux collatz.c
Open Watcom C32 Optimizing Compiler Version 1.9
[…]
collatz.c: 27 lines, included 712, 0 warnings, 0 errors
Code size: 67
$ wlink FILE collatz.o FORMAT ELF NAME collatz
Don't specify FORMAT this prevents using default SYStem entry

Specify SYStem linux but not neccessary for building on the same OS
see WATCOM/binl/wlsystem.lnk for defaults

so minimal compile/link is
wcc386 collatz
wlink fi collatz

or

wcl386 collatz

CU
Frank
Götz Hoffart
2013-12-02 20:01:53 UTC
Permalink
Post by Frank Beythien
so minimal compile/link is
wcc386 collatz
wlink fi collatz
or
wcl386 collatz
$ wcl386 collatz.c
[...]
wcc386 collatz.c
[...]
collatz.c: 27 lines, included 712, 0 warnings, 0 errors
Code size: 70
[...]
Warning! W1115: file wlink.lnk: line(20): environment name WATCOM not found
Error! E2093: file wlink.lnk: line(20): cannot open /binl/wlsystem.lnk
Error: Linker returned a bad status
I invoked ". /opt/watcom/owsetenv.sh" before trying to compile, but
WATCOM is not defined there.
Post by Frank Beythien
WATCOM=/opt/watcom wcl386 collatz.c
[...]
wcc386 collatz.c
[...]
collatz.c: 27 lines, included 712, 0 warnings, 0 errors
Code size: 70
[...]
loading object files
searching libraries
creating a Linux x86 executable
Muuuch better :-) Thanks a lot.

Are there any "wrapper" scripts to make the behaviour more UNIX-like?
That collatz-test was a try to see how things work. Now I'd like to
build an open source package (<http://ngircd.barton.de>) that relies on
autoconf & automake.

But:

~/src/ngircd-21 $ CC=/opt/watcom/binl/wcl386 ./configure
gives:
configure:3401: checking for C compiler default output file name
configure:3403: result: conftest
configure:3409: checking for suffix of executables
configure:3416: /opt/watcom/binl/wcl386 -o conftest conftest.c >&5
Open Watcom C/C++32 Compile and Link Utility Version 1.9
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
wcc386 conftest.c -o
Open Watcom C32 Optimizing Compiler Version 1.9
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
Error! E1074: Invalid optimization option ''
conftest.c: 18 lines, included 35, 0 warnings, 1 errors
Error: Compiler returned a bad status compiling 'conftest.c'
wcc386 conftest.c -o
Open Watcom C32 Optimizing Compiler Version 1.9
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
Error! E1074: Invalid optimization option ''
conftest.c: 18 lines, included 35, 0 warnings, 1 errors
Error: Compiler returned a bad status compiling 'conftest.c'
configure:3420: $? = 1
configure:3436: error: in `/home/goetz/src/ngircd-21':
configure:3438: error: cannot compute suffix of executables: cannot
compile and link

Regards
Götz
Frank Beythien
2013-12-02 21:33:55 UTC
Permalink
Post by Götz Hoffart
Post by Frank Beythien
so minimal compile/link is
wcc386 collatz
wlink fi collatz
or
wcl386 collatz
$ wcl386 collatz.c
[...]
wcc386 collatz.c
[...]
collatz.c: 27 lines, included 712, 0 warnings, 0 errors
Code size: 70
[...]
Warning! W1115: file wlink.lnk: line(20): environment name WATCOM not found
In my owsetenv.sh WATCOM is defined with the basedir (where owsetenv.sh
is). I'm mot sure how it got there.
Post by Götz Hoffart
Are there any "wrapper" scripts to make the behaviour more UNIX-like?
Not that I know of, but you are welcome to contribute...
Linux is a later addition, the roots are with DOS, OS/2 and WINxx.
Post by Götz Hoffart
That collatz-test was a try to see how things work. Now I'd like to
build an open source package (<http://ngircd.barton.de>) that relies on
autoconf & automake.
~/src/ngircd-21 $ CC=/opt/watcom/binl/wcl386 ./configure
I don't think specifying wcl386 (combined compile and link) for cc will
work, but I'm neither linux nor configure expert.

The Watcom toolchain is a bit different due to its age and the cross
compile features. Especially Wlink is quite different with options and
directives.

CU
Frank
Hans-Bernhard Bröker
2013-12-02 23:04:51 UTC
Permalink
Post by Frank Beythien
Post by Götz Hoffart
~/src/ngircd-21 $ CC=/opt/watcom/binl/wcl386 ./configure
I don't think specifying wcl386 (combined compile and link) for cc will
work,
I'm utterly certain it won't. That's a job the other OW compiler
driver, "owcc", was specifically created to do.

Unless that ./configure was built by a massively outdated autoconf, your
base for experimentation should be

./configure CC=owcc CXX=owcc

Or probably better yet, do an out-of-srcdir build if the package allows it:
mkdir build_OW
cd build_OW
../configure CC=owcc CXX=owcc

That way you can have a GCC-based build right next to it, without the
two getting their rays crossed:

mkdir build_gcc
cd build_gcc
../configure

BTW, yes, I do suggest you put OW on the $PATH, at least for shells in
which you plan on using it with any kind of intensity.
Jiri Malak
2013-12-02 22:19:08 UTC
Permalink
What you have in owsetenv.sh?

Jiri
Dave Yeo
2013-12-03 04:47:40 UTC
Permalink
Post by Götz Hoffart
Are there any "wrapper" scripts to make the behaviour more UNIX-like?
That collatz-test was a try to see how things work. Now I'd like to
build an open source package (<http://ngircd.barton.de>) that relies on
autoconf& automake.
Try using owcc, which is a POSIX-like compiler driver. Something like
./configure CC=owcc LD=owcc may work.
Documentation is in C/C++ Tools User's Guide.
Dave
Continue reading on narkive:
Loading...