How do I run source code in a mac terminal? - c

Please please help me, I am a computer illiterate female looking to convert a group of (.cng files) into jpegs. I found a source code on a blog that instructs me to
Build it, then run it with something like this:
cng2jpg /path/to/images/199x/1990101/*.cng
Here is a link to the source code
Does anyone know how I can run the source code to convert the files?
Here is a link to the blog post for reference for what exactly I am doing

First, put the source code into a file named cng2jpg.c. Then open a terminal, navigate with cd into the directory where you placed that file and type
cc -o cng2jpg cng2jpg.c
This creates the program cng2jpg. You can execute it by typing
path/to/cng2jpg input_file.cng
where path/to/cng2jpg is the path where cng2jpg was generated in the previous step.

Related

How do I link a compiled ".so" library with Scons?

I have an existing .so library (libgit2), and I would like to use this within a C program (the build system is Scons). I read through the entirety of the Scons documentation for "Chapter 4. Building and Linking with Libraries", but there is no mention of how to use an existing .so library. The only mention of .so in the entirety of chapter 4 is on the first page, and it is only about Scons using a .so file for output. How do I use an existing compiled .so library in Scons?
If you are using an sconscript then you should add a LIBS= arguments and a LIBS_PATH=.
if you want to directly add it to the build line, use -L for lib path and -l to link a lib.
You can find further information here: https://scons.org/doc/0.97/HTML/scons-user/x628.html
With help from the SCons Discord server and other places, I've gotten farther than when I first posted this question. I haven't solved my specific problem of using .so libraries with GDNative, but I think I've figured out the SCons side.
As of me posting this question, the SConstruct file was able to compile working code if I didn't use libgit2 and instead just printed out the text. With only the header included, my test call to git_libgit2_version compiled but didn't run, as Godot said undefined symbol: git_libgit2_version.
First of all, you need to add the named parameter for LIBS to your env.SharedLibrary or env.Program line. The lib prefix and .so suffix seem to be added automatically, I still haven't figured out how to make it point to libgit2.so.1.0.1 (so for now I have the library copied and named as libgit2.so, but I would like to have it point to libgit2.so.1.0.1 eventually instead). Also, the SCons team suggested adding LIBPATH, but this doesn't seem to actually do anything.
library = env.SharedLibrary(target=env["target_path"] + env["target_name"] , source=sources, LIBS=['git2'])
Then, the SConstruct file needs to have this magic line:
env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
With the above code, ldd will report not found, and Godot will say Error: libgit2.so.1.0: cannot open shared object file: No such file or directory (I have no idea why it's asking for .so.1.0 instead of the .so or .so.1.0.1 file, and yes I tried copying and naming as libgit2.so.1.0 and that doesn't change anything either).
I also added this, which was suggested by another GDNative user.
env.Append(LINKFLAGS=[
'-Wl,-rpath,addons/git_for_godot/gdnative/linuxbsd'
])
With all of the above code, this seems to allow ldd and Godot to find the library just fine with a relative path (when running ldd you have to be cd'd into the project folder). I can run the project fine without any errors, but the project crashes immediately after opening, with no error messages printed. If I comment out the call to git_libgit2_version but keep the header included, the file does compile and run. Any time I try to call anything from libgit2 it causes Godot to crash without printing any errors. At this point I'm stuck and I don't know what I'm doing wrong.
I did try adding libgit2 to the Dependencies section of the .gdnlib file, but this doesn't seem to affect anything. Another thing I tried which didn't work is this line (+ variants on the extension) which append to the sources list passed as the named source parameter. I'll post it here for completeness, but for the moment I have this line commented out because it doesn't work:
sources.append(File("project/addons/git_for_godot/gdnative/linuxbsd/libgit2.so"))

GCC cannot recognize the directory path inside a file

The problem I encountered in using GCC is that I cannot use the command make to build my program because some files contain the paths of their actual location.
Say I have a file named "machine.h", its content is target-pisa/pisa.h. At the same time, in the same working directory, I have a folder named "target-pisa", in which there is a file named "pisa.h"; the actual code of the header file "machine.h" is actually inside the file "pisa.h", which is inside the folder named "target-pisa" located in the same working directory as "machine.h".
Assume for some reason I cannot simply copy and paste the code from "pisa.h" to "machine.h"; that is, I have to stick with what is provided by the prof. The make command does not work in this case in my laptop because it cannot interpret target-pisa/pisa.h as a directory path and open the actual header file "pisa.h" according to the path target-pisa/pisa.h provided in the file "machine.h". Instead, git bash interprets target-pisa/pisa.h as C code (if I am not mistaken); see the figure below.
Some additional info that may be helpful:
In machine.h, there is only one line of code as shown below:
target-pisa/pisa.h
I have checked that almost all .c files in the working directory have #include "machine.h".
How can I solve this problem? Please help, I have been stuck in this for a long time. By the way, my friend also used git bash to do this lab and this problem doesn't happen to him.
I tried to reinstall git bash in order to see if the problem can be solved, but it didn't.
All in all, I want to build the program successfully by using make command in git bash.
machine.h needs to have an #include directive to tell the compiler to pull in the nested header.
#include "target-pisa/pisa.h"
Just writing target-pisa/pisa.h by itself isn't valid C code.

CodeBlocks - How to add an icon to a C program?

I have a small C console program and I want to add an .ico file to it, so that the executable looks nice.
How can I do this in CodeBlocks with MinGW/gcc?
I could not find relevant help via google that a total beginner (like me for C) could follow, so I will Q&A this topic.
First of all you need an .ico file. Put it in the folder with your main.c file.
In CodeBlocks go to File -> New -> Empty File and name it icon.rc. It has to be visible in the Workspace/Project otherwise CodeBlocks will not be aware of this file. It will show up there in a project folder called Resources .
Put the following line in it: MAINICON ICON "filename.ico". MAINICON is just an identifier, you can choose something different. More info 1 & More info 2.
Save the files and compile - CodeBlocks will do everything else for you
What will happen now, is windres.exe (the Resource Compiler) compiling the resource script icon.rc and the icon to an object binary file to obj\Release\icon.res. And the linker will add it to the executable.
It's so easy yet it took me quite a while to find it out - I hope I can save someone else having the same problem some time.

NASM setting in Vistual Studio13

I am creating a library, which require some assembly level code.
I am using using NASM to write and integrate my .asm file.
Now the problem is, I already have a project created in VS13. Now I want to add and integrate an assembly level code to my project.
I have already added a .asm file in my source directory, but when I am trying to run my test case, the compiler is unable to find my assembly code.
I want to know how can I link my .asm file with my .c file.
Structure of my project:
->Project1(Generates a Library)
--->Source
----->File1.c
----->File2.c
----->nasm.asm
->Project2 (Test case to use the library and generate .exe)
-->Source
---->main.c
Now, nasm.asm binaries should get attached with the .lib generated by project1
and Project2 should able to access project1.lib
Apologize if question is bit unclear, its a bit complex for me to make it clear in written. Please let me know if you want any clarification or extra information.
Thanks a lot
For each of you assembly files:
Right click it in the Solution Explorer and choose Properties
Make sure the selected Configuration is either All Configurations or the configuration you are using (this bites me every time!)
In the Configuration Properties>General change the Item type to Custom Build Tool
From the Configuration Properties>Custom Build Tool>General set the following items:
Command Line. Use this as an example: nasm -fwin32 "%(FullPath)" -o %(Filename).obj
Outputs. This is necessary, VS check for this files. I usually use %(Filename).obj.
Link Objects. Yes. If you name your output files with obj extension they are automatically included in the link phase.
To check that you set everything right, select your assembly file, right click and choose Compile.

Netbeans EXE not working when executed from Terminal - CentOs

I made Netbeans work environment with SASL. The sample codes get build and it also run properly from Netbeans. But when I try to run my exe from Terminal it is not working. The error says as below:
./cppapplication_1: error while loading shared libraries:
libanonymous.so.2: cannot open shared object file: No such file or
directory
I tried setting the PATH using the below Command :
export PATH=/usr/lib64/sasl2/:$PATH
Still I am getting the same error. Do I need anything extra to do?
You need to add the path to libanonymous to the enviroment variable LD_LOAD_LIBRARY.
Update:
To do so:
Locate the library, for example doing: find / -name "libanonymous.so.2" or by locate libanonymous.so.2
Add the path found like so: export LD_LOAD_LIBRARY=$LD_LOAD_LIBRARY:<path to lib>
Update 1:
From your comment to Anon's answer I see that the lib in question is located under /usr/lib64/sasl2/.
So you might like to set LD_LOAD_LIBRAY path like so:
export LD_LOAD_LIBRARY=$LD_LOAD_LIBRARY:/usr/lib64/sasl2/
Update 2
This needs to be done in the same shell that later then executes the program needing the libraries (cppapplication_1).
cd <dir for cppapplication_1>; export LD_LOAD_LIBRARY=$LD_LOAD_LIBRARY:/usr/lib64/sasl2/; ./cppapplication_1
You can also try this.
ldd <name of executable>
You will see dependent libs and their expected paths. See if the lib is present at the path executable is expecting.

Resources