Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
311 votes
4 answers
168k views

What are the differences between .so and .dylib on macOS?

.dylib is the dynamic library extension on macOS, but it's never been clear to me when I can't / shouldn't use a traditional unix .so shared object. Some of the questions I have: At a conceptual ...
Trent Davies's user avatar
  • 3,469
238 votes
16 answers
143k views

Finding current executable's path without /proc/self/exe

It seems to me that Linux has it easy with /proc/self/exe. But I'd like to know if there is a convenient way to find the current application's directory in C/C++ with cross-platform interfaces. I've ...
Uros Dimitrijevic's user avatar
192 votes
16 answers
140k views

Can't compile C program on a Mac after upgrade to Mojave

I have used the gcc command on the terminal to compile C programs but all of a sudden, after an update to my Mac's OS (to macOS 10.14 Mojave, and XCode 10.0), I started receiving the message: test.c:...
Maxxx's user avatar
  • 3,748
178 votes
19 answers
647k views

How can I compile and run C/C++ code in a Unix console or Mac terminal?

How can I compile/run C or C++ code in a Unix console or a Mac terminal?
P-A's user avatar
  • 11.1k
123 votes
4 answers
9k views

Why does rand() repeat numbers far more often on Linux than Mac?

I was implementing a hashmap in C as part of a project I'm working on and using random inserts to test it. I noticed that rand() on Linux seems to repeat numbers far more often than on Mac. RAND_MAX ...
Theron S's user avatar
  • 1,353
122 votes
10 answers
390k views

How can I run a C program on Mac OS X using Terminal?

I am new to C. Here is my "Hello, World!" program. #include <stdio.h> int main(void) { printf("Hello, World!\n"); return 0; } After I try to run it using Terminal it ...
Bolat Tleubayev's user avatar
108 votes
8 answers
303k views

How do I compile a .c file on my Mac?

How do I compile a .c file on my Mac?
David's user avatar
  • 14.8k
104 votes
16 answers
77k views

Can't compile a C program on a Mac after upgrading to Catalina 10.15

There's a previous question Can't compile C program on a Mac after upgrade to Mojave, and the answers to that have covered most of the variations on what goes wrong. Now — as of Monday 2019-10-07 — ...
Jonathan Leffler's user avatar
87 votes
10 answers
100k views

How to Compile for OS X in Linux or Windows?

I would like to port my C/C++ apps to OS X. I don't have a Mac, but I have Linux and Windows. Is there any tool for this?
Unknown's user avatar
  • 46.5k
77 votes
5 answers
80k views

readelf-like tool for Mac OS X? [closed]

Is there a tool for reading Mac OS X binaries that would print information about relocation tables and symbol offsets similar to this readelf output? readelf -r app Relocation section '.rel.dyn' at ...
karlphillip's user avatar
  • 92.9k
73 votes
13 answers
101k views

clock_gettime alternative in Mac OS X

When compiling a program I wrote on Mac OS X after installing the necessary libraries through MacPorts, I get this error: In function 'nanotime': error: 'CLOCK_REALTIME' undeclared (first use in this ...
Delan Azabani's user avatar
68 votes
5 answers
109k views

List of all users and groups

I'm trying to get a list of all users and all groups on Mac OS X 10.5+. How can I do this? For example, the list of all users on my machine should return: _amavisd, _appowner, _appserver, _ard, ...
Dave DeLong's user avatar
66 votes
3 answers
38k views

sem_init on OS X

I am working on some code which uses the pthread and semaphore libraries. The sem_init function works fine on my Ubuntu machine, but on OS X the sem_init function has absolutely no effect. Is there ...
Nippysaurus's user avatar
  • 20.2k
63 votes
6 answers
43k views

Which macro to wrap Mac OS X specific code in C/C++

While reading various C and C++ sources, I have encountered two macros __APPLE__ and __OSX__. I found plenty of use of __OSX__ in various codes, especially those originating from *BSD systems. ...
mloskot's user avatar
  • 38.1k
63 votes
1 answer
3k views

Weak symbol aliases on OS X similar to those on Linux, or a closest equivalent?

What I do When writing shared libraries for Linux, I tend to pay attention to relocations, symbol visibility, GOT/PLT etc. When applicable, I am trying to avoid calling PLT stubs when functions from ...
user avatar
60 votes
6 answers
156k views

Typing "gcc --version" outputs clang version instead on mac

I am using OS 10.9 on mac machine. I want to know the version of gcc I am using. So I tried gcc --version on terminal and it results : $ gcc --version Configured with: --prefix=/Applications/Xcode5-...
subhash kumar singh's user avatar
60 votes
2 answers
15k views

Why Swift is 100 times slower than C in this image processing test? [duplicate]

Like many other developers I have been very excited about the new Swift language from Apple. Apple has claimed its speed is faster than Objective C and can be used to write operating system. And from ...
Penghe Geng's user avatar
  • 14.1k
51 votes
2 answers
32k views

Why are sem_init(), sem_getvalue(), sem_destroy() deprecated on Mac OS X — and what replaces them?

When I compile a program using the POSIX sem_init() function, I get a compilation warning (error because I normally use -Werror) that the function has been deprecated when I compile on Mac OS X 10.10....
Jonathan Leffler's user avatar
48 votes
8 answers
83k views

How do you do non-blocking console I/O on Linux in C?

How do you do nonblocking console IO on Linux/OS X in C?
nonpolynomial237's user avatar
43 votes
4 answers
95k views

How to set up libusb on Mac OS X?

I'd like to try to make a user-space device driver using libusb on Mac, but I'm confused where to start. In the SDK installer (which I got from http://www.ellert.se/twain-sane) it said something about ...
Dae's user avatar
  • 2,387
41 votes
3 answers
35k views

Creating static Mac OS X C build

How can i create a static build of a .c file on Mac OS X ? When i try: gcc -o test Main.c -static I get: ld: library not found for -lcrt0.o collect2: ld returned 1 exit status
Daniel's user avatar
  • 3,047
39 votes
6 answers
25k views

How to convert ASCII character to CGKeyCode?

I need a function that, given a character, returns the CGKeyCode associated with the position of that character on the current keyboard layout. E.g., given "b", it should return kVK_ANSI_B if using U....
Michael's user avatar
  • 11.9k
37 votes
6 answers
32k views

Nano syntax highlighting in Mac OS X 10.7 (Lion)?

How to enable syntax highlighting for nano in Mac OS X 10.7 (Lion)? According to what I found so far on Google is that it has got to do with /.nanorc file. I have no idea how to get it or make it? ...
sukhvir's user avatar
  • 5,475
36 votes
9 answers
12k views

editline/history.h and editline/readline.h not found/working on macOS when trying to compile with developer tools installed already

I am working on this tutorial on building your own LISP (http://www.buildyourownlisp.com/chapter4_interactive_prompt) and for some reason when I try to compile I get this: REPL.c:4:10: fatal error: '...
yburyug's user avatar
  • 1,070
36 votes
7 answers
106k views

Good C IDE for Mac? [closed]

I've just started a job where I'm programming in C on a Mac, which is my first experience using a Mac for development. For now I'm using Xcode as my editor, then using make/gcc/svn at the command line ...
Graphics Noob's user avatar
36 votes
8 answers
26k views

`"<program>" would like to access files in your Documents folder` message with VS Code and macOS Catalina

I'm using Visual Studio Code with the C/C++ official extension from Microsoft to write C programs, running under macOS Catalina 10.15.3. The project folder lies in a path within the Documents folder ...
swineone's user avatar
  • 2,684
35 votes
5 answers
52k views

Where is the standard C library on Mac OS X?

I am trying to find the standard C library on Mac OS X. I've tried paths like: "/usr/lib/libc.a" or "/usr/lib/libm.a" , but there aren’t such files on the system. Where can I find ...
Oliver 's user avatar
  • 603
35 votes
3 answers
13k views

Retrieve names of running processes

First off, I know that similar questions have been asked, but the answers provided haven't been very helpful so far (they all recommend one of the following options). I have a user application that ...
Dave DeLong's user avatar
32 votes
10 answers
55k views

Where is my "stdio.h" in Mac?

I know that Mac OS X is a Unix-based system. And I heard that C standard library such as stdio.h, is located in /usr/local/include or /usr/include. But there is not any kind of library in this ...
user3595632's user avatar
  • 5,590
31 votes
2 answers
10k views

Cross compiling GCC with newlib for ARM: how to specify GCC options like -march?

I've compiled GCC along with newlib on Mac OS X for ARM targets. However, libc.a was compiled with -fshort-enums, and I don't want that because when I compile stuff for ARM, I use -fno-short-enums. ...
Synthetix's user avatar
  • 2,105
30 votes
7 answers
27k views

Creating a windowed application in pure C on MacOS

I'm creating an application in pure C on Mac OSX. What I want is to create a window in which my app will be displayed. Preferably I want it to be pure C solution, but if I have to use Objective-C ...
Mago's user avatar
  • 495
30 votes
2 answers
45k views

How to install gtk on OSX for use with g++/gcc compiler

I already asked this question at apple.stackexchange.com, but I was told it was the wrong place for this question - so I will ask it here, as I was suggested to do. At my university we got the task ...
tmuecksch's user avatar
  • 6,552
29 votes
7 answers
31k views

Programmatically retrieving the absolute path of an OS X command-line app

On Linux, an application can easily get its absolute path by querying /proc/self/exe. On FreeBSD, it's more involved, since you have to build up a sysctl call: int mib[4]; mib[0] = CTL_KERN; mib[1] =...
Benjamin Pollack's user avatar
29 votes
5 answers
24k views

Unknown ending signal when using debugger gdb

I have installed GDB on Mac OS X and to test that it works I have used this following C program. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int *...
Pierre P.'s user avatar
  • 1,055
29 votes
4 answers
20k views

GCC left shift overflow

The following little program is very awkward using GCC version 4.2.1 (Apple Inc. build 5664) on a Mac. #include <stdio.h> int main(){ int x = 1 << 32; int y = 32; ...
Lucas's user avatar
  • 481
27 votes
6 answers
22k views

How can a file contain null bytes?

How is it possible that files can contain null bytes in operating systems written in a language with null-terminating strings (namely, C)? For example, if I run this shell code: $ printf "Hello\00, ...
RK.'s user avatar
  • 887
27 votes
3 answers
73k views

What is `S_ISREG()`, and what does it do?

I came across the macro S_ISREG() in a C program that retrieves file attributes. Unfortunately, there isn't any basic information about this macro online. There are some more advanced discussions on ...
The Pointer's user avatar
  • 2,316
27 votes
2 answers
8k views

Detect in C if outputting to a terminal

I'm writing a C program for OS X and Linux, and I want to tweak the output based on whether or not it's going to a terminal. I know we've covered how to do this in a shell script, e.g. here: ...
Paul A Jungwirth's user avatar
27 votes
1 answer
11k views

Cannot get lldb to read file input through redirect

I'm using lldb as a standalone debugger in OSX. I'm trying to debug a C executable, using a text file as input, by way of a redirect. The lldb documentation specifies the following command for ...
Harald Husum's user avatar
  • 1,149
27 votes
5 answers
15k views

Is a Linux executable "compatible" with OS X?

If you compile a program in say, C, on a Linux based platform, then port it to use the MacOS libraries, will it work? Is the core machine-code that comes from a compiler compatible on both Mac and ...
bgroenks's user avatar
  • 1,879
26 votes
6 answers
9k views

How come a 32 bit kernel can run a 64 bit binary?

On my OS X box, the kernel is a 32-bit binary and yet it can run a 64-bit binary. How does this work? cristi:~ diciu$ file ./a.out ./a.out: Mach-O 64-bit executable x86_64 cristi:~ diciu$ file /...
diciu's user avatar
  • 29.3k
26 votes
10 answers
8k views

Can gdb make a function pointer point to another location?

I'll explain: Let's say I'm interested in replacing the rand() function used by a certain application. So I attach gdb to this process and make it load my custom shared library (which has a ...
karlphillip's user avatar
  • 92.9k
26 votes
3 answers
12k views

Build Apple Silicon binary on Intel machine

How can I compile a C project on macOS 11 (Intel) to work on Silicon? My current build script is as simple as: ./configure make sudo make install I've tried using the --host and --target flags with ...
Till's user avatar
  • 1,100
25 votes
5 answers
42k views

endian.h not found on mac osx

I meet some trouble when I compile some C code on my mac which give me this error : fatal error: 'endian.h' file not found I did some google search about this problem.It seems like mac os x ...
geasssos's user avatar
  • 429
25 votes
8 answers
22k views

Reading Other Process' Memory in OS X?

I've been trying to understand how to read the memory of other processes on Mac OS X, but I'm not having much luck. I've seen many examples online using ptrace with PEEKDATA and such, however it doesn'...
Jeremy's user avatar
  • 1
25 votes
3 answers
17k views

Default libraries linked in by gcc?

Let's say I have a very simple C file (called foo.c): int main() { printf("foo"); return 0; } Now I call gcc: gcc foo.c When I call gcc (with no options, as in the above example), what ...
user1516425's user avatar
  • 1,561
24 votes
1 answer
20k views

Do I really need libgcc?

I've been using GCC 4.6.2 on Mac OS X 10.6. I use the -static-libgcc option when I compile, otherwise my binaries look for libgcc on the system and I'm not sure anything over GCC 4.2 is supported on ...
Synthetix's user avatar
  • 2,105
23 votes
8 answers
32k views

How to guarantee 64-bit writes are atomic?

When can 64-bit writes be guaranteed to be atomic, when programming in C on an Intel x86-based platform (in particular, an Intel-based Mac running MacOSX 10.4 using the Intel compiler)? For example: ...
23 votes
6 answers
16k views

What C preprocessor conditional should I use for OS X specific code?

What C preprocessor conditional should I use for OS X specific code? I need to include a specific library if I am compiling for OS X or a different header if I am compiling for Linux. I know there is ...
klynch's user avatar
  • 1,076
22 votes
3 answers
16k views

How use Instruments and display the console in Command Lines applications [duplicate]

I'm using Xcode on OSX to develop command line C applications. I would also like to use Instruments to profile and find memory leaks. However, I couldn't find a way to display the console when ...
Hugo Sereno Ferreira's user avatar

1
2 3 4 5
63