`cpp_source()` fails if there are hyphens in the filename

Open
#248 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp, r
Domain
compilers

Research direction

Start at the cpp11::cpp_source entry point and reproduce the reported case with a temporary C++ filename containing a hyphen. Trace how the filename contributes to the generated symbol, then verify that compilation succeeds and some_function() can be called for hyphenated filenames.

Written by the indexing model from the issue text.

Description

I imagine this isn't the intended behaviour but also has a very easy workaround (don't use hyphens in a C++ source filename).

temp <- tempfile(fileext = "contains-hyphen.cpp")
write("
#include <cpp11.hpp>

[[cpp11::register]]
void some_function() {}      
", temp)

cpp11::cpp_source(temp)
#> /private/var/folders/gt/l87wjg8s7312zs9s7c1fgs900000gn/T/Rtmp9b1IjL/file1045918f3e435/src/cpp11.cpp:5:43: error: expected ';' after top level declarator
#> extern "C" SEXP _file1045977566e56contains-hyphen_some_function() {
#>                                           ^
#>                                           ;
#> 1 error generated.
#> make: *** [/private/var/folders/gt/l87wjg8s7312zs9s7c1fgs900000gn/T/Rtmp9b1IjL/file1045918f3e435/src/cpp11.o] Error 1
#> make: *** Waiting for unfinished jobs....
#> Error: Compilation failed.
some_function()
#> Error in some_function(): could not find function "some_function"

Created on 2021-11-10 by the reprex package (v2.0.1)

Dominant language
C++
Stars
224
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/cpp11

All issues in r-lib/cpp11

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.