# Travis cannot locate standard C++ functionality?

**URL:** <https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196>\
**Category:** C++\
**Created:** [July 12, 2019, 8:00pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196 "2019-07-12T20:00:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 12, 2019, 8:00pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/1 "2019-07-12T20:00:43Z")

</div>

Hi folks,

I’m just trying to figure out why Travis is failing my build when I build locally completely fine. You can see from here that things like printf() and other standard C/C++ code is undefined:

[https://travis-ci.org/ButchDean/interactive\_computer\_graphics/jobs/558002721](https://travis-ci.org/ButchDean/interactive_computer_graphics/jobs/558002721)

I’m pretty sure I am missing something here but don’t know what it is.

Any help appreciated!

Thanks.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [July 12, 2019, 8:29pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/2 "2019-07-12T20:29:13Z")

</div>

It was working before [https://travis-ci.org/ButchDean/interactive\_computer\_graphics/jobs/556928323](https://travis-ci.org/ButchDean/interactive_computer_graphics/jobs/556928323)

What changed?

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 13, 2019, 12:49am UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/3 "2019-07-13T00:49:51Z")

</div>

Okay, let me put it another way. Why does it build cleanly locally but not on Travis? If it had the same errors locally I would know it is because I missed a standard include.

Clearly this is likely to do with my Travis file but I don’t know what it is.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 13, 2019, 12:56am UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/4 "2019-07-13T00:56:39Z")

</div>

From the errors, you are clearly missing `#include <cstdio>`.

> [@ButchDean](#):
>
> Why does it build cleanly locally but not on Travis?

Typical reasons are:

- Forgot to commit something
- Using a different compiler/environment (e.g. envvars) that results in it implying the include or something
- Build cache

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 13, 2019, 1:32am UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/5 "2019-07-13T01:32:54Z")

</div>

It’s only likely to be the second one in building on a different environment. My branch is certainly clean and I performed clean builds to test.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 13, 2019, 1:55am UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/6 "2019-07-13T01:55:52Z")

</div>

So I built on old RedHat 6 and the latest Ubuntu and both build cleanly. I know for sure there is something wrong with the way I’ve written my .travis.yml file.

Anybody have any idea still?

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [July 13, 2019, 1:59am UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/7 "2019-07-13T01:59:44Z")

</div>

> **[ButchDean/interactive\_computer\_graphics](https://github.com/ButchDean/interactive_computer_graphics/compare/ff0d7a2...57c566e4155b84ba40ffdb4ae94c2dc2e7862509)**
>
> Interactive Computer Graphics by Edward Angel Linux Versions - ButchDean/interactive\_computer\_graphics

Here’s the diff between the last successful build on `master` and the first failure showing this problem. The obvious difference is the use of `g++-6` package from `ubuntu-toolchain-r-test`. I would start from there.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 13, 2019, 4:10am UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/8 "2019-07-13T04:10:01Z")

</div>

Yes, I changed it because the old way wasn’t working after my code changes. Now this other way isn’t working either.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 13, 2019, 5:28pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/9 "2019-07-13T17:28:54Z")

</div>

I’ll try several more things later and if it still won’t work I’ll remove it from the project.

Thanks.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 13, 2019, 8:13pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/10 "2019-07-13T20:13:24Z")

</div>

Why not just fix your code rather than juggling with tools to make them accept broken code?

It’s your call, of course, but don’t expect help with doing a wrong thing ('cuz it would have you come back here begging for help when it crashes on you again).

It’s standard practice to include all public headers whose functionality a source file directly uses, even if they are implicitly included from elsewhere.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 15, 2019, 12:43pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/11 "2019-07-15T12:43:58Z")

</div>

If it builds locally without issue then it is Travis’ fault. I organized the code in such a way that the headers are in one place and appropriately referenced, it builds fine locally. I have seen other CI systems and currently work with them (like Jenkins) that deal with really badly organized code.

Once again, if my code builds without issue locally over multiple Linux distros then Travis should not require me to reorganize already working code to work around its deficiencies - that is not how CI works.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [July 15, 2019, 1:36pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/12 "2019-07-15T13:36:08Z")

</div>

> [@ButchDean](#):
>
> If it builds locally without issue then it is Travis’ fault.

I do not believe this is a fair statement. The fact that your tests pass on your machine could mean that your machine contains some files necessary for the tests, whereas on the CI machines those are missing or different versions are used for whatever reason (e.g., CI doesn’t provide certain packages by default, you made local changes to your code or dependencies that don’t get reflected in CI, CI pulls down the most recent versions of your dependencies which introduces incompatibilities).

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 15, 2019, 1:42pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/13 "2019-07-15T13:42:55Z")

</div>

But I tried on both RedHat and Ubuntu. Sorry to seem like a dick, but I simply am not convinced, especially since nothing has been offered to look into Travis itself rather than “it’s your project structure/code changes”.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 15, 2019, 2:17pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/14 "2019-07-15T14:17:14Z")

</div>

When I look at the code and see that it uses `stdio` function but has no `#include <cstdio>`, I look no further. That’s a language violation, it shouldn’t work according to the language standard. So even if it happens to work for you for some reason, it’s an unsupported use case and Travis cannot guarantee that it’ll work.

As for the possible reason, [https://stackoverflow.com/questions/57033333/what-implementation-of-getenv-is-used-if-no-header-is-included](https://stackoverflow.com/questions/57033333/what-implementation-of-getenv-is-used-if-no-header-is-included) suggests that in some compiler versions, code with undefined functions might compile but crash at runtime. Maybe under some circumstances, the compiler can even link such a functon to some definition (e.g. if you do include this header in some other compilation unit). If this is the case, the compiler violates (relaxes) the language standard and as such, there’s no guarantee that other compilers or even other versions of the same compiler will work the same.

That’s exactly what standards are for: if you compily, you are officially guaranteed predictable behavior, and people will be fixing things if it’s not delivered. If you don’t, no-one guarantees you anything, any result (including errors and random behavior) is possible.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 15, 2019, 3:45pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/15 "2019-07-15T15:45:06Z")

</div>

This is ultimately C code and I cannot touch the actual source. I’ve been building the code with GCC7 and 8. If what you say is true then it likely should be reflected on my setup.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 15, 2019, 4:12pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/16 "2019-07-15T16:12:00Z")

</div>

So I gave the benefit of doubt to you guys are also tried to be more specific with the .travis.yml script and it is still failing. Instead of using stdio.h I used cstdio on a new branch (fixingtravis).

> <https://github.com/ButchDean/interactive_computer_graphics/commits/fixingtravis>

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [July 15, 2019, 5:05pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/17 "2019-07-15T17:05:31Z")

</div>

This snippet

```auto
#include <cstdio>

int main() {
  printf("hello world\n");
  return 0;
}

```

[works](https://travis-ci.org/BanzaiMan/travis_production_test/builds/559021809#L181-L186), and [updating to `g++-6` also works](https://travis-ci.org/BanzaiMan/travis_production_test/builds/559023627#L329-L334).

Something else in your setup is causing this problem. I don’t know enough about your code to comment much further than this.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 15, 2019, 5:24pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/18 "2019-07-15T17:24:46Z")

</div>

Oh yes, I’m well aware of other code working. If you look at some other projects on my profile you will see that it works fine for those specific applications, and was working up to a point with this project. What I’m trying to get to is the ‘why’ this is happening and how to fix it.

As I said before, if I can build locally successfully every time locally then technically Travis CI should not have any issues either, which to me is a given. Imagine having a development environment for dev machines where collaborative work builds when they clone the repo and build locally, then they all make changes and merge them locally and everything still goes well. Now, they push this merged code that builds up to the CI environment and it breaks, clearly this is to do with either the CI environment being specifically broken or it cannot accurately mimic the target platform(s).

I appreciate all your efforts in answering, I simply don’t buy that I’m specifically doing something wrong in the C++ code.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [July 15, 2019, 5:50pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/19 "2019-07-15T17:50:32Z")

</div>

I’m happy to enable the debug feature so you can troubleshoot your issue further. Just let me know.

---

<div class="post-metadata">

**Author:** ![ButchDean](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/butchdean/32/2244_2.png) [@ButchDean](https://travis-ci.community/u/ButchDean)\
**Post date:** [July 16, 2019, 12:45pm UTC](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196/20 "2019-07-16T12:45:51Z")

</div>

Thank you, BanzaiMan, I would appreciate that.

[Next page](https://travis-ci.community/t/travis-cannot-locate-standard-c-functionality/4196.md?page=2)
