I am unable to compile C code on neither MacOS Catalina nor Big Sur. I see the header files present in /usr/include/, but I get errors from my C compiler.
Current error messages I get from the compiler are:
For "#include <time.h>" => error: cannot open source file "time.h"
For "#include <stdint.h>" => error: cannot open source file
"stdint.h"
What I've tried:
I tried sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target / and it says "upgrade successful", but does not resolve any errors.
I tried uninstalling and reinstalling XCode (Version 10.1)
I tried downloading the .pkg file you mentioned (because I was missing it) but was told my macOS version was too new
The files I need are stored in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include, so we added a new CPATH and PATH variable (separately) for that path to ~/.bash_profile and /etc/paths
I tried to provide #include statements with explicit paths to those files, which quickly spiraled out of control
I tried to move all of the required files from the above directory to my project folder and changing the paths appropriately in the code
I tried to run sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
The files should also be stored in Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include, so I tried doing the above steps with this path as well
Any advice would be helpful. Thank you!
To provide more clarity based on a comment from Joshua below, these are the steps I followed to set up the 32-bit ARM cross-compiler:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
brew install gmp
brew install mpfr
brew install libmpc
Downloaded "binutils-2.36.tar.xz" from here
Outside of the binutils directory, created a directory called
"build32"
../binutils-2.36/configure --target=arm-none-eabi --disable-nls --enable-languages=c --without-headers
make -j4 all
sudo make install
Downloaded "gcc-arm-src-snapshot-10.2-2020.11.tar.xz" from here
Inside the main directory, created a subdirectory called "build32"
../gcc-arm-src-snapshot-10.2-2020.11/configure --target=arm-none-eabi --disable-nls --enable-languages=c --without-headers
make -j4 all-gcc
sudo make install-gcc
I ended up switching to a Windows Subsystem for Linux setup on another machine for what I was working on. Another option is to set up a VM on the Mac. I could not figure out another solution for getting it to "just work" on the Mac. Thanks to everyone for the suggestions!
For those looking to pivot to WSL, follow this setup guide.
For those looking to go the VM workaround route, this is one process that was graciously recommended to me:
"1. Install Virtualbox from https://www.virtualbox.org/
Install Vagrant from https://www.vagrantup.com/
Download the prebuilt ARM gcc cross compiler from the link above in my question.
Move the download file into the project directory and run the following command to extract it:
tar -xvf gcc-arm-10.2-2020.11-x86_64-arm-none-eabi.tar.xz
Download this Vagrantfile (fyi 'this' triggers a download of said file) and move it to the project directory as
well. This file tells vagrant how to setup the VM. It will mount the
project directory as well as the SD card. On line 41 of this file it
tells vagrant where the SD card is located so change the first path
on this line to where your SD card is located. Additionally, because
the project directory is mounted, you can still edit the project
files locally on your machine instead of having to use what's on the
VM if you use this solution.
After all that, you should be ready to create/start the VM using the
command vagrant up. To log into the VM, vagrant ssh after the
vagrant up command finishes. Your project files should be located in
the /vagrant directory. You are now all setup to compile the project
and if you run make cp it should compile the project and copy it
over to the SD card.
To shutdown the VM you can run vagrant halt to shutdown the VM, and
to get rid of the VM you can run vagrant destroy. vagrant destroy
will not delete any of the files that were shared from your computer
to the VM."
Related
in the new version of putty there is no Makefile.vc or project file for visual studio. How can I compile putty under visual studio 2019? can someone help me?
link to zipped source
I tried to open the windows folder in visual studio with the following error:
Severity Code Description Project File Line Suppression State
Error CMake Error at C:\Usersuser\Downloads\Compressed\putty-src\windows\CMakeLists.txt:3 (add_sources_from_current_dir):
Unknown CMake command "add_sources_from_current_dir". C:\Users\user\Downloads\Compressed\putty-src\windows\CMakeLists.txt 3
You don't need to open Visual Studio or any IDE to compile the executables.
Download cmake and make sure Visual C compiler is installed.
Unzip the .zip file, open a command prompt where the readme and CMakeLists.txt reside
Then, as the readme states:
run these commands in the source directory:
cmake .
cmake --build .
In the Debug directory, you'll find a lot of .exe files.
Then, to install in the simplest way on Linux or Mac:
cmake --build . --target install
I didn't need that part. I suppose that it copies the executables & other files somewhere in the path.
Problem with creating a distro using Microsoft compiler is that the executables then require a lot of Microsoft runtime DLLs. For instance if you deploy the executables on other machines it may not work.
An alternative is to use gcc and make to build the executables.
First:
install a recent gcc for windows
install make
Installing a recent MinGW distribution should do it. Personally I used another gcc distribution so I had to grab make too.
Now, I followed Setting default compiler in CMake, the key part being to enable mingw makefiles: -G "MinGW Makefiles", else cmake ignores your compiler requirements and keeps on using Microsoft compiler.
cmake -DCMAKE_MAKE_PROGRAM=/path/to/make/make.exe -DCMAKE_C_COMPILER=/path/to/gcc/gcc.exe -G "MinGW Makefiles" .
Note that specifying full paths require that / are used. Backslashes conflict with escaping in cmake/make files.
Then
cmake --build .
I was going through the beginner tutorial and came to the Atom SDK page. I have a windows system, so installing brew doesn't work, but the tutorial only gives a way for Linux systems or Mac OS systems to install Pact. Is there any way to install Pact onto windows?
There is no official support for Windows (to my knowledge), but there is a possible workaround that worked for me. The workaround involves Ubuntu and WSL(Windows Subsystem for Linux).
The first step is installing Ubuntu and WSL in your windows device. Those who have done this could move ahead to step two. I followed this Youtube video for setting up WSL
With WSL Terminal set up, go to the terminal home directory and download the compressed pact executable from the official pact releases Github, suiting your ubuntu version, using command line curl. An example command I used for Ubuntu 20.04 and Pact v4.3 is:
curl -LJO https://github.com/kadena-io/pact/releases/download/v4.3/pact-4.3-linux-20.04.zip
3.Install unzip on command line using:
sudo apt install unzip
Unzip the compressed executable to the same directory using the unzip command. ex:
unzip pact-4.3-linux-20.04.zip`
this will add a pact.exe file on that directory
Update the user permissions on the pact.exe file using chmod command to enable read and execute.
chmod u=rx ./pact
Add the directory with pact executable to terminal permanent search path. This is done by exporting a new path in the .bash_profile file. (Editing .bash_profile could be done through any command line text editor e.g. vim). I followed this tutorial to complete this step.
And that should allow you to start pact from a windows wsl terminal.
I am trying to learn C/C++ programming by following the MIT OCW materials. I am running a Windows PC and the course material mandates running all C/C++ programs under the Linux environment with the gcc/g++ compiler (for C and C++). They also require the use of gdb and valgrind as a debugger.
I have already installed gcc/g++ from the MinGW package and am wondering if there is a specific instructions on how I can achieve the setup. For now I'd like to be able to set up the Linux, gdb, and valgrind and at least write a simple program and compile and run it in the Linux environment. For now I've also installed VirtualBox but for some reason the virtual machine I created always gives the following message: FATAL: No bootable medium found! System halted.
I guess I am just lost in all the software packages/tools that are needed in order to start the learning. I've only used Microsoft Visual Studio before and so these whole new command prompts and tools are really confusing to me. Would be great if someone could give me the specific instructions on how I can start from a Windows PC and arrive at compiling and debugging a simple C program with gdb and valgrind in the Linux environment.
I recommend you use VirtualBox to create a virtual machine. This is best because it sandboxes your development environment and you get a real Linux environment to work in. VirtualBox is free and open source and you probably won't need any advanced features you might see in VMWare or Parallels.
Download VirtualBox (https://www.virtualbox.org/wiki/Downloads)
Download Ubuntu server (https://www.ubuntu.com/download/server)
Create a new virtual machine (VM)
Mount the Ubuntu ISO file to the VM (Settings -> Storage, check 'Live CD/DVD' and click the disk icon to browse for the ISO)
Boot up the VM and install Ubuntu by following the on-screen instructions
Now that you have the environment built you can create a directory where your project folders go. From the prompt just do mkdir projects, cd projects, mkdir helloworld, cd helloworld. Then, you can use the built-in editor nano to edit files. Type nano hello.c and then enter the following:
#include <stdio.h>
int main()
{
printf("Hello, world\n");
}
Then type Ctrl-O to write out and then Ctrl-X to exit.
Then you just need to install gcc and I would suggest installing make as well:
$ sudo apt install gcc
...
$ sudo apt install make
Now to compile and test your first program in your development environment:
$ make hello
$ ./hello
Then you should see Hello, world on your screen.
Valgrind and Un-mount Disk
From your helloworld project folder enter sudo apt install valgrind, then run valgrind ./hello.
Finally, go to Settings -> Storage and un-mount the installation ISO.
SSH Access
Install openssh-server using the following command:
sudo apt install openssh-server
Find the IP address of your Ubuntu host by typing ifconfig. Then for VirtualBox go to Settings :: Network :: Advanced and click Port Forwarding. Use these settings:
Host IP: 127.0.0.1
Host Port: 22
Guest IP: (IP of Ubuntu VM)
Guest Port: 22
Now you can ssh to your Ubuntu VM and also use tools like scp.
Shared Folders
Shared folders allow you to have a medium that spans both file systems, allowing you to share files between the two environments. This resource offers a lot more detail in the different methods: https://www.virtualbox.org/manual/ch04.html#sharedfolders. I will go over how to set this up quickly in the setup detailed here.
The following will install the Linux headers required for VirtualBox shared folders:
sudo apt-get install build-essential linux-headers-`uname –r`
Then go to the Devices tab of the VirtualBox menu and click Insert Guest Additions CD image....
Now we need to mount the cdrom and run the script:
sudo mount /dev/cdrom /media/cdrom
sudo /media/cdrom/VBoxLinuxAdditions.run
Figure out what Windows folder you want to share, and share it by going to VirtualBox guest Machine :: Settings :: Shared Folders and add it with the options Auto-mount and Make Permanent. When you're done, do a sudo reboot.
The shared folders are automatically added and exist in /media/sf_*.
You must be in the vboxsf group to work with those files. Use this command to add a user testuser to that group:
sudo usermod -aG vboxsf testuser
sudo reboot
After I followed the instructions in (Building Custom ModSecurity Modules)section in modsecurity dev guide in order to compile (mod_tfn_reverse.c) using the command apxs -ca mod_tfn_reverse.c, I'm still finding "fatal errors" such as unable to find the file modsecurity.h mentioned in the header of the C document.
Here is the link to the source on github modsec
Instructions I did:
I am using Ubuntu 14.4 64bits (New installation with updates).
I installed "apache dev" package, to run "APXS" command on terminal.
Downloaded "modsecurity" zip file from github.
I extracted the zip file, then I located where the mod_tfn_reverse.c is.
It's path : ModSecurity/ext/mod_tfn_reverse.c
Then I changed the directory to the targeted file CD modsecurity/ext
as I placed the folder in "home".
Finally, I executed the command apxs -ca mod_tfn_reverse.c.
These are the instructions I did, apxs works, but the compilation fails because "modsecurity.h" declared in the header was not found, I searched this file I found it in another directory (ModSecurity/apache2/modsecurity.h).
So, the difficulty is, how can I successfully compile that specific file and have the module done and ready to use in apache2 server.
I am also confused about what are the other archives, headers, and development tools required to:
to compile a custom apache module.
to compile mod_tfn_reverse.c, in my case, knowing that this is only the starting point to create custom module for modsecurity.
This is covered by the included README:
apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
-ca mod_tfn_reverse.c
I tried to compile the Linux kernel on the host machine to be installed in the virtual machine. The obvious gain here is performance.
I have been using the following steps after copying over the ".config" file from the VM:
$ export CONCURRENCY_LEVEL=9
$ fakeroot make-kpkg --initrd --append-to-version=-myext-0.1 kernel_image kernel_headers
However, I am noticing a behavior where the compilation/packaging packages symlinks for the header files rather than the header files themselves. This behavior is fine if I am installing the packages on the same machine. However, when I copy the packages to the VM and install them, all I have installed are symlinks to files that do not exist in the VM. They exist on the host machine.
Anyone knows how to fix this? I could be missing a flag or something of that sort.