# Error compiling ex\_field\_utils.c building vtk

**URL:** https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442
**Category:** Support
**Created:** [August 21, 2024, 7:09am UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442 "2024-08-21T07:09:18Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![gib](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gib/32/9201_2.png) [@gib](https://discourse.vtk.org/u/gib)
#### Post date: [August 21, 2024, 7:09am UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/1 "2024-08-21T07:09:18Z")

</div>

I am using VS 2019 to build the vtk-9.3 source code I fetched from [https://gitlab.kitware.com/vtk](https://gitlab.kitware.com/vtk).  
The errors are in line 30 of ex\_field\_utils.c"

static size\_t my\_strlcat(char \*restrict dst, const char \*restrict src, size\_t maxlen)

|Error|C2061|syntax error: identifier ‘dst’  
|Error|C2059|syntax error: ‘;’  
|Error|C2059|syntax error: ‘,’  
|Error|C2059|syntax error: ‘)’

My C++ knowledge is not sufficient to tell me what is wrong with this line.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [August 21, 2024, 11:17am UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/2 "2024-08-21T11:17:37Z")

</div>

The “restrict” keyword is a C keyword, but not a C++ keyword. The closest MSVC equivalent is “\_\_restrict” with two underscores.

---

<div class="post-metadata">

### Author: ![gib](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gib/32/9201_2.png) [@gib](https://discourse.vtk.org/u/gib)
#### Post date: [August 21, 2024, 11:20am UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/3 "2024-08-21T11:20:37Z")

</div>

As you can see, David, I’m no C expert either. Can you tell me what the error is in line 30, and how to fix it?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [August 21, 2024, 11:24am UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/4 "2024-08-21T11:24:27Z")

</div>

VS 2019 doesn’t doesn’t recognize “restrict” so it reports a syntax error. If you replace restrict with \_\_restrict, it should compile.

---

<div class="post-metadata">

### Author: ![gib](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gib/32/9201_2.png) [@gib](https://discourse.vtk.org/u/gib)
#### Post date: [August 21, 2024, 11:31am UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/5 "2024-08-21T11:31:06Z")

</div>

That worked.

Thanks.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 26, 2024, 2:52pm UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/6 "2024-08-26T14:52:53Z")

</div>

Hi,

VS’s `cl` compiler has a C compiler, which is used when the source file ends with `.c`. So, changing `restrict` to `__restrict` signals something is amiss. You can get this specific line to compile, but you can stumble upon other problems such as C++ mangling symbols (in C it doesn’t happen).

So, I’d advise against tweaking C code just to be compilable by a C++ compiler. Instead, you should investigate why the C++ compiler is being called to compile C code, which is wrong. C code should be compiled with a C compiler and that’s that.

best,

PC

---

<div class="post-metadata">

### Author: ![gib](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gib/32/9201_2.png) [@gib](https://discourse.vtk.org/u/gib)
#### Post date: [August 26, 2024, 10:11pm UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/7 "2024-08-26T22:11:53Z")

</div>

That’s above my pay-grade, Paulo. I’d assume that VTK developers, cmake and VS 2019 know how to ensure that the right compiler is used.

Cheers,

Gib

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [August 26, 2024, 10:55pm UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/8 "2024-08-26T22:55:05Z")

</div>

> [@Paulo\_Carvalho](#):
>
> VS’s `cl` compiler has a C compiler,

Yes, but with regards to `restrict`, the C compiler in VS2017 and VS2019 does not conform with C99. It’s not that the wrong compiler is being used, it’s that Visual Studio has a history of not supporting features of C unless those features also exist in C++.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 27, 2024, 5:37pm UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/9 "2024-08-27T17:37:43Z")

</div>

Microsoft indeed has a decades-long history of some moronic decisions regarding its development tools. A proper, fully compliant C support in Windows can be found in MinGW64’s GCC if you’re willing to develop software written in C without issues. Either this or upgrade to VS 2022. I’ve just compiled VTK 9.3 with that version without any C syntax-related issues.

---

<div class="post-metadata">

### Author: ![gib](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gib/32/9201_2.png) [@gib](https://discourse.vtk.org/u/gib)
#### Post date: [August 27, 2024, 10:36pm UTC](https://discourse.vtk.org/t/error-compiling-ex-field-utils-c-building-vtk/14442/10 "2024-08-27T22:36:22Z")

</div>

After fixing the “restrict” error the VTK build completed without problems. Onwards and upwards.
