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

Add example of loading at runtime from C #248

Merged
merged 5 commits into from
Oct 16, 2024
Merged

Add example of loading at runtime from C #248

merged 5 commits into from
Oct 16, 2024

Conversation

WardBrian
Copy link
Collaborator

Recently a few requests have come in around using BridgeStan from C/C++, but in a way that is more closely aligned with how it is used in the other languages, e.g. providing a path to the library, rather than re-linking your code.

This adds an alternative example that does just that. It also adds some extra config so we can run some of these examples in the Windows CI -- the statically linked one isn't working for me, so I left it out for now still.

@WardBrian WardBrian added the documentation Improvements or additions to documentation label Oct 16, 2024
Copy link
Owner

@roualdes roualdes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, thanks, Brian. Just a couple of questions.

@@ -28,3 +34,6 @@ example_static$(EXE): example.c ../test_models/$(MODEL)/$(MODEL)_model.a
$(CC) -c -I ../src example.c -o example.o
$(LINK.cpp) -o example_static$(EXE) example.o ../test_models/$(MODEL)/$(MODEL)_model.a $(LDLIBS) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS)
$(RM) example.o

example_runtime$(EXE): runtime_loading.c
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it reasonable to add ../test_models/$(MODEL)/lib$(MODEL)_model.$(DLL) here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would cause example_runtime to be re-built more often, which feels like it goes against the pedagogical purpose of the example. Strictly speaking, there is no reason that any bridgestan library needs to have been compiled before this, which is what that dependency would be saying

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goes against the pedagogical purpose of the example

Right, good point.

Is it reasonable to leave the code suggestion in the Readme as is, then add a sentence or two explaining that example_runtime the executable can be compiled, but not run without a .so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the readme block:

make example_runtime
# unlike above, this did not automatically build a model, since it
# was not needed to _build_, but we still need one to _run_ the program
make ../test_models/full/full_model.so
./example_runtime ../test_models/full/full_model.so

c-example/README.md Outdated Show resolved Hide resolved
c-example/runtime_loading.c Show resolved Hide resolved
Copy link
Owner

@roualdes roualdes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@WardBrian WardBrian merged commit e273c8d into main Oct 16, 2024
19 checks passed
@WardBrian WardBrian deleted the c-runtime-example branch October 16, 2024 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants