Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined reference to `Main_runtime_override_defaults_oo' #3464

Closed
presidentbeef opened this issue Feb 13, 2020 · 4 comments · Fixed by #3975
Closed

Undefined reference to `Main_runtime_override_defaults_oo' #3464

presidentbeef opened this issue Feb 13, 2020 · 4 comments · Fixed by #3975
Labels
needs discussion Needs to be discussed further

Comments

@presidentbeef
Copy link
Contributor

I am just trying to get basic C linking working.

Upfront, this is the error:

/bin/ld: /home/justin/.local/share/ponyup/ponyc-release-0.33.2-x86_64-linux-gnu/lib/x86-64/libponyrt.a(start.o): in function `pony_init':
start.c:(.text+0x91): undefined reference to `Main_runtime_override_defaults_oo'
collect2: error: ld returned 1 exit status

Main_runtime_override_defaults_oo was added recently in 0.33.0 so I'm guessing it just isn't exposed correctly in libponyrt.a

I think this is easy for Pony developers to reproduce, but just in case I'm doing something wrong, here is what I did:

I have a tiny Pony file called try_pony.pony:

actor@ Try
  new create() =>
    None

I compile it with ponyc --library to get try_pony.h and libtry_pony.a.

Then I have a tiny C file called test.c:

#include <stdio.h>
#include "try_pony.h"
#include "pony.h"

int main(int argc, char** argv) { 
  pony_init(argc, argv);

  Try* x = Try_Alloc();
  Try_tag_create_o__send(x);

  pony_start(true, NULL, NULL);
  return 0;
}

Then I compile like this:

export PONYRT_INCLUDE=/home/justin/.local/share/ponyup/ponyc-release-0.33.2-x86_64-linux-gnu/include/
export PONYRT_LIB=/home/justin/.local/share/ponyup/ponyc-release-0.33.2-x86_64-linux-gnu/lib/x86-64/libponyrt.a

gcc -o test -I. -I $PONYRT_INCLUDE \
    -g -rdynamic -mcx16 test.c libtry_pony.a $PONYRT_LIB -lpthread -ldl -latomic

This results in the error above.

Now, if I do the dumbest thing possible and add this to my C file:

void Main_runtime_override_defaults_oo(void* opt)
{
  return;
}

Then it compiles fine.

@SeanTAllen
Copy link
Member

After looking at this, I believe you are required to add the function yourself in your case at the moment.

@jemc do you concur based on looking at how it currently exists?

@jemc
Copy link
Member

jemc commented Feb 13, 2020

Yeah, based on how it currently exists, doing what OP called "the dumbest thing possible" is the correct way to get this to work. That is, adding a definition like this will make it work:

void Main_runtime_override_defaults_oo(void* opt)
{
  (void)opt; // avoid warning/error about unused variable
  return;
}

Currently, this works in Pony programs by the Pony compiler generating a default implementation of this method if the program had none:

// If have no @runtime_override_defaults method, add one.
if(has_member(members, "runtime_override_defaults"))
return;
ast_append(members, make_runtime_override_defaults(ast));

For more general info about this feature, see https://github.com/ponylang/ponyc/blob/b6265be32d39b371a1b4b9f8dba8cf71c74fd578/packages/builtin/runtime_options.pony

Is this the cleanest way this feature could have been implemented? Maybe not, because it makes some assumptions about only using the Pony runtime with the ponyc compiler, and as we can see in this issue ticket, it inconveniences uses of Pony for generating C API functions.

It might be worth revisiting how this might be implemented in a cleaner way.

@presidentbeef
Copy link
Contributor Author

Just want to point out that I didn't mean "the dumbest thing possible" in a derogatory way, I'm just not much of a C programmer so I don't know what makes sense.

Thanks!

@jemc
Copy link
Member

jemc commented Feb 13, 2020

Yeah, I didn't take it in a derogatory way - I just found it to be a funny situation and was glad to see that you got the workaround right on your first try.

@SeanTAllen SeanTAllen added the needs discussion Needs to be discussed further label Mar 30, 2021
SeanTAllen added a commit that referenced this issue Jan 29, 2022
From the very early days of the Pony runtime, a "library mode" has been around that allows you to compile a Pony program to a C compatible library that you can then start up using various runtime APIs to do things like initialize the runtime, create actors, send messages and more. We've made extensive changes to the runtime over the years and have no faith that library mode and its related functionality work.

Our lack of faith extends back many years and we've stated as the Pony core team that we don't consider library mode to be supported; until now, we haven't done anything about what "not supported" means. This commit is the first move in removing support for using the Pony runtime via the various untested C API functions.

Additional changes will be made to take various PONY_API methods that we consider to be "internal only" and rename them to be `ponyint_` to clarify that they aren't intended for calling from external source and to remove PONY_API methods that aren't used internally by the runtime or the standard library.

Closes #3464 
Closes #1882
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion Needs to be discussed further
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants