# Struggling with ccall

**URL:** <https://discourse.julialang.org/t/struggling-with-ccall/28427>\
**Category:** General Usage\
**Created:** [September 5, 2019, 12:54pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427 "2019-09-05T12:54:45Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 5, 2019, 8:16pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/21 "2019-09-05T20:16:15Z")

</div>

I’m not at home now but I hust installed the latest version so it should be that one.

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 11:21am UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/22 "2019-09-06T11:21:59Z")

</div>

Julia Version 1.2.0  
Commit c6da87ff4b (2019-08-20 00:03 UTC)  
Platform Info:  
OS: Windows (x86\_64-w64-mingw32)  
CPU: Intel(R) Core™ i5-4670 CPU @ 3.40GHz  
WORD\_SIZE: 64  
LIBM: libopenlibm  
LLVM: libLLVM-6.0.1 (ORCJIT, haswell)

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 6, 2019, 12:41pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/23 "2019-09-06T12:41:26Z")

</div>

Does gcc build a 64-bit library by default under mingw?

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 1:22pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/24 "2019-09-06T13:22:29Z")

</div>

I don’t know. How can I check it?

---

<div class="post-metadata">

**Author:** ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)\
**Post date:** [September 6, 2019, 1:56pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/25 "2019-09-06T13:56:27Z")

</div>

FWIW, I don’t know much about interpreting output from `nm`.

But my return symbols in 16 Hex (64-bit),

```julia
0000000067e813b0 T prob

```

Your seems to be in 32-bit with 8 Hex

```julia
68081290 T _prob

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 6, 2019, 2:09pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/26 "2019-09-06T14:09:43Z")

</div>

You might have installed 32-bit mingw. You need 64-bit distro.

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 2:11pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/27 "2019-09-06T14:11:53Z")

</div>

Can someone link me the right version I should install?  
Thank you very much for your help!! 😀

---

<div class="post-metadata">

**Author:** ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)\
**Post date:** [September 6, 2019, 5:34pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/28 "2019-09-06T17:34:01Z")

</div>

I get mine from here:  
[http://mingw-w64.org/doku.php/download/mingw-builds](http://mingw-w64.org/doku.php/download/mingw-builds)

It is an Window online installer, be sure to pick `x86_64` over `i686` for 64-bit, I don’t know if `win32` vs. `posix` Threads make a difference, nor `dwarf` vs. `sjlj`. So you might want to do some reading yourself, if you are particular about these things/

---

<div class="post-metadata">

**Author:** ![jmkuhn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmkuhn/32/2090_2.png) [@jmkuhn](https://discourse.julialang.org/u/jmkuhn)\
**Post date:** [September 6, 2019, 5:36pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/29 "2019-09-06T17:36:55Z")

</div>

Run  
`gcc -dumpmachine`  
For a 64 bit install the output should be `x86_64-w64-mingw32`. If it starts with `i686-` you will be compiling for 32 bit.

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 5:54pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/30 "2019-09-06T17:54:08Z")

</div>

> [@jmkuhn](#):
>
> gcc -dumpmachine

I get `mingw32`

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 5:55pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/31 "2019-09-06T17:55:06Z")

</div>

I did this when I installed the first time…  
I’ll try again  
Do you know how I can uninstall the old mingw before install the new one?

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 6:12pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/32 "2019-09-06T18:12:56Z")

</div>

Ok, I installed the version you suggested me and updated the path, this is the gcc --version result.

```julia
gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

```

I’ll try to run opendl asap!

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 6:19pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/33 "2019-09-06T18:19:17Z")

</div>

Ok, I cannot believe it but opendl now works and gives this as a result:

`Ptr{Nothing} @0x0000000067e80000`

BUUUUUUT…  
when I try to run the ccall line, Julia crashes and I cannot see which is the error because the window closes.  
What’s the problem now?

---

<div class="post-metadata">

**Author:** ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)\
**Post date:** [September 6, 2019, 6:23pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/34 "2019-09-06T18:23:33Z")

</div>

yea… so… I also get seg fault using your code.

> signal (11): Segmentation fault

Something about your c-code is not right, it is accessing address it shouldn’t have(?). If you change your dimension `a` to be `100 x 2` and `b` to be `3 x 100`, you will get something. So I will leave it back to you to debug the c-code.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 6, 2019, 6:52pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/35 "2019-09-06T18:52:19Z")

</div>

Multi dimentional arrays are not pointers to pointers etc. in c. You shouldn’t declare you c code like that unless you really have to.

---

<div class="post-metadata">

**Author:** ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)\
**Post date:** [September 6, 2019, 7:46pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/36 "2019-09-06T19:46:40Z")

</div>

Sorry but I’m not an expert as my code suggests.  
What am I supposed to do to include this piece of code in Julia and make it work?  
I’m working on a package I want to publish in the next weeks so this ccall() must work also in the package.  
I thought that calling C or C++ from Julia was simpler than in the other high level languages but it doesn’t seem like that. For example in R is way more easy.

Please let me know if you can help me and thank you in advance!

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [September 7, 2019, 12:13pm UTC](https://discourse.julialang.org/t/struggling-with-ccall/28427/37 "2019-09-07T12:13:43Z")

</div>

The hard part is that `**a`(pointer to the pointer) and a matrix in julia are not the same thing. when `a[i][j]` is used for a pointer to pointer in c, it first dereference `a[i]` (ith memory block after pointer in a) to get the address of the row i and then (\*a[i])[j] get dereferenced to get the element in column j, whereas julia `Matrix` is contiguous memory mapped values(Note said c representation is not necessarily contiguos row after row. I say row it depends how you interpret dimensions. It can very well be thought as the reverse(as columns)) However, direct definitions with known sizes is a contiguous memory mapped matrix in c like `float a[5][], b[6][7];` .

[Previous page](https://discourse.julialang.org/t/struggling-with-ccall/28427.md?page=1)
