# \[ampl 24758\] c++20

**URL:** https://discuss.ampl.com/t/ampl-24758-c-20/694
**Category:** Google Group Mirror
**Created:** [August 25, 2023, 3:15pm UTC](https://discuss.ampl.com/t/ampl-24758-c-20/694 "2023-08-25T15:15:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Matheus\_Diogenes\_And](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/matheus_diogenes_and/32/380_2.png) [@Matheus\_Diogenes\_And](https://discuss.ampl.com/u/Matheus_Diogenes_And)
#### Post date: [August 25, 2023, 3:15pm UTC](https://discuss.ampl.com/t/ampl-24758-c-20/694/1 "2023-08-25T15:15:18Z")

</div>

Hello everyone.

I am trying to run AMPL C++ API with C++20, but I am having some problems with this. Inside my AMPL folder **_/opt/ampl/amplapi/examples/cpp_** , I type:

**_g++ -std=c++11 -Wall -o firstexample firstexample.cc -I…/…/include -L…/…/lib -lampl_**

As suggested here [https://groups.google.com/g/ampl/c/QAPhvArF7Bs/m/4NnDJs13BAAJ](https://groups.google.com/g/ampl/c/QAPhvArF7Bs/m/4NnDJs13BAAJ). Which works just fine, but if I try to do the same by using c++20

**_g++ -std=c++20 -Wall -o firstexample firstexample.cc -I…/…/include -L…/…/lib -lampl_**

I get the following messages:

**_In file included from …/…/include/ampl/amplexception.h:8,_**  
**_from …/…/include/ampl/ep/errorinfo\_ep.h:6,_**  
**_from …/…/include/ampl/variant.h:7,_**  
**_from …/…/include/ampl/ep/arg.h:4,_**  
**_from …/…/include/ampl/dataframe.h:4,_**  
**_from …/…/include/ampl/ampl.h:4,_**  
**_from firstexample.cc:3:_**  
**_…/…/include/ampl/format.h: In instantiation of ‘void fmt::internal::MemoryBuffer\<T, SIZE, Allocator\>::grow(std::size\_t) [with T = wchar\_t; long unsigned int SIZE = 500; Allocator = std::allocator\<wchar\_t\>; std::size\_t = long unsigned int]’:_**  
**_…/…/include/ampl/format.h:799:6: required from here_**  
**_…/…/include/ampl/format.h:802:30: error: no matching function for call to ‘fmt::internal::MemoryBuffer\<wchar\_t, 500, std::allocator\<wchar\_t\> \>::allocate(std::size\_t&, std::nullptr\_t)’_**  
**_802 | T new\_ptr = this-\>allocate(new\_capacity, FMT\_NULL);_**  
_\_\__| ~~^~~~~~ _\_\_  
 **In file included from /usr/include/c++/11/string:41,**  
 **from /usr/include/c++/11/bits/locale\_classes.h:40,**  
 **from /usr/include/c++/11/bits/ios\_base.h:41,**  
 **from /usr/include/c++/11/ios:42,**  
 **from /usr/include/c++/11/ostream:38,**  
 **from /usr/include/c++/11/iostream:39,**  
 **from firstexample.cc:1:**  
 **/usr/include/c++/11/bits/allocator.h:179:7: note: candidate: ‘constexpr \_Tp** _ **_std::allocator\< \>::allocate(std::size\_t) [with \_Tp = wchar\_t; std::size\_t = long unsigned int]’_**  
 **_179 | allocate(size\_t \_\_n)_**  
\_\_\*| ^~_\_\_  
\_\__/usr/include/c++/11/bits/allocator.h:179:7: note: candidate expects 1 argument, 2 provided\*\_\_  
 **_In file included from …/…/include/ampl/amplexception.h:8,_**  
 **_from …/…/include/ampl/ep/errorinfo\_ep.h:6,_**  
 **_from …/…/include/ampl/variant.h:7,_**  
 **_from …/…/include/ampl/ep/arg.h:4,_**  
 **_from …/…/include/ampl/dataframe.h:4,_**  
 **_from …/…/include/ampl/ampl.h:4,_**  
 **_from firstexample.cc:3:_**  
 **_…/…/include/ampl/format.h: In instantiation of ‘void fmt::internal::MemoryBuffer\<T, SIZE, Allocator\>::grow(std::size\_t) [with T = char; long unsigned int SIZE = 500; Allocator = std::allocator; std::size\_t = long unsigned int]’:_**  
 **_…/…/include/ampl/format.h:799:6: required from here_**  
 **_…/…/include/ampl/format.h:802:30: error: no matching function for call to ‘fmt::internal::MemoryBuffer\<char, 500, std::allocator \>::allocate(std::size\_t&, std::nullptr\_t)’_**  
 **_802 | T new\_ptr = this-\>allocate(new\_capacity, FMT\_NULL);_**  
_\_\__| ^ ~~~~~ _\_\_  
 **In file included from /usr/include/c++/11/string:41,**  
 **from /usr/include/c++/11/bits/locale\_classes.h:40,**  
 **from /usr/include/c++/11/bits/ios\_base.h:41,**  
 **from /usr/include/c++/11/ios:42,**  
 **from /usr/include/c++/11/ostream:38,**  
 **from /usr/include/c++/11/iostream:39,**  
 **from firstexample.cc:1:**  
 **/usr/include/c++/11/bits/allocator.h:179:7: note: candidate: ‘constexpr \_Tp** _ **_std::allocator\< \>::allocate(std::size\_t) [with \_Tp = char; std::size\_t = long unsigned int]’_**  
 **_179 | allocate(size\_t \_\_n)_**  
\_\_\*| ^~~~_\_\_  
\_\__/usr/include/c++/11/bits/allocator.h:179:7: note: candidate expects 1 argument, 2 provided\*\_\_

I would like to know if someone ever tried using the AMPL C++ API with C++20.

Thanks and best regards.

---

<div class="post-metadata">

### Author: ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)
#### Post date: [August 25, 2023, 3:21pm UTC](https://discuss.ampl.com/t/ampl-24758-c-20/694/2 "2023-08-25T15:21:07Z")

</div>

The version of the API currently being distributed has a different format.h file which was adjusted to allow compiling with C++20 some time ago. Could you please upgrade to the latest version and try again?

---

<div class="post-metadata">

### Author: ![Matheus\_Diogenes\_And](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/matheus_diogenes_and/32/380_2.png) [@Matheus\_Diogenes\_And](https://discuss.ampl.com/u/Matheus_Diogenes_And)
#### Post date: [August 25, 2023, 3:36pm UTC](https://discuss.ampl.com/t/ampl-24758-c-20/694/3 "2023-08-25T15:36:33Z")

</div>

I did a small test, I changed the line 802 of file **_/opt/ampl/amplapi/include/ampl/format.h_** from

**_T \*new\_ptr = this-\>allocate(new\_capacity, FMT\_NULL);_**

to

**_T \*new\_ptr = this-\>allocate(new\_capacity);_**

And now it works fine. Is it some setting from my side or a lack in AMPL?

Thanks and BR.

---

<div class="post-metadata">

### Author: ![Matheus\_Diogenes\_And](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/matheus_diogenes_and/32/380_2.png) [@Matheus\_Diogenes\_And](https://discuss.ampl.com/u/Matheus_Diogenes_And)
#### Post date: [August 25, 2023, 3:47pm UTC](https://discuss.ampl.com/t/ampl-24758-c-20/694/4 "2023-08-25T15:47:02Z")

</div>

Sorry, just saw the other comment. Problem solved, just had to update to the most recent version.

Thank you very much.

---

<div class="post-metadata">

### Author: ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)
#### Post date: [August 25, 2023, 3:45pm UTC](https://discuss.ampl.com/t/ampl-24758-c-20/694/5 "2023-08-25T15:45:32Z")

</div>

The issue is that the version of the API you are using was exposing an old version for fmtlib. Even though that fix got it to compile, it is possible that you may face some other issues. The current version of the API does not depend on it anymore.
