Compilation error calling `patsopt_version` (undefined reference)

27 views
Skip to first unread message

spearman

unread,
Mar 8, 2017, 7:55:34 PM3/8/17
to ats-lang-users
Trying to call `patsopt_version` in the following simple program:

#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

implement main0
() = (
  println
!(patsopt_version());
  exit_errmsg_void
(0, "foo\n")
)

generates the compiler error:

/tmp/cc8XdQB8.o: In function `mainats_void_0':
patsver_dats.c:(.text+0x181): undefined reference to `
atspre_patsopt_version'
collect2: error: ld returned 1 exit status

and a couple warnings:

patsver_dats.c: In function mainats_void_0’:
patsver_dats
.c:343:1: warning: implicit declaration of function atspre_patsopt_version [-Wimplicit-function-declaration]
 
ATSINSmove(tmp2, atspre_patsopt_version()) ;
 
^
In file included from patsver_dats.c:15:0:
/home/spearman/ats/remote/ATS2-Postiats/ccomp/runtime/pats_ccomp_instrset.h:270:35: warning: assignment makes pointer from integer without a cast [enabled by default]
 
#define ATSINSmove(tmp, val) (tmp = val)
                                   
^
patsver_dats
.c:343:1: note: in expansion of macro ATSINSmove
 
ATSINSmove(tmp2, atspre_patsopt_version()) ;
 
^

Commenting out the line to call `patsopt_version` compiles and runs successfully emitting the exit message.

Hongwei Xi

unread,
Mar 8, 2017, 8:45:09 PM3/8/17
to ats-lan...@googlegroups.com

Thanks for reporting it!

I fixed the issue and uploaded the changes to GitHub, which should go into
the next release (ATS2-0.3.4).

By the way, patsopt_version is NOT a template. So one needs -latslib when using it.
I forgot the need to compile patsopt_version when generating the libatsopt library.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/b0b17fed-0eae-4113-95cf-3f93b266571c%40googlegroups.com.

spearman

unread,
Mar 8, 2017, 11:42:54 PM3/8/17
to ats-lang-users
Thank you.

I am a little unclear on when `-latslib` needs to be linked (at least it isn't discussed in the introduction book or tutorial, nor the wiki except to say that it should be avoided for portable libraries).

I can see that `fun patsopt_version() = "mac#%"` is an "external global name" (treated as a C macro). Is it then required to link `-latslib` whenever a definition is of an external global name? i.e. `ext#`, `mac#` or `sta#`?

I did also find an implementation in `prelude/DATS/basics.dats` which has a simple definition: `implement patsopt_version() = "0.3.2"` which doesn't look like an "external" C macro (maybe this definition is unrelated?)

You also mentioned that it was not compiled when generating libatsopt, which seems to be a different static library `ccomp/atslib/lib/libatsopt.a`, is it necessary to also link this library in some cases with `-latsopt` ?
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.

gmhwxi

unread,
Mar 9, 2017, 12:00:35 AM3/9/17
to ats-lang-users

Most of ATS library is template-based. There is no need for -latslib
if only templates are used.

>>fun patsopt_version() = "mac#%"

This means that patsopt_version is treated as a C macro. More precisely,
it means that the compiler never generates an interface for patsopt_version
in the generated C code.

I now feel that this is a mistake. Instead, I now declare patsopt_version as follows:

fun patsopt_version() = "ext#%"

This means that patsopt_version is treated as a C function. If used, its C interface
needs to be generated.

Only when you use functions (not function templates) implemented in ATSLIB, you
need to have -latslib.

>>generating libatsopt

Sorry, it was a typo. Should be libatslib.

As for libatsopt, it is essentially the library version of patsopt. It is primarily used for
building utilities for processing ATS code (e.g., syntax hi-lighting).
Reply all
Reply to author
Forward
0 new messages