How do i link 2 object files to form a binary file - ld

I have tried using ld to link 2 .o files together with this,
ld -T link.ld -o kernel.bin kernel.o ks.o
but it produce an error saying
ld: cannot open linker script file link.ld: No such file or directory
Is there anything wrong with my commands or do i have to create a path or something?

You need to create the "linker script" link.ld. Google "linker script" for docs.

Related

Portable check for library

A project I am trying to compile has this command:
cc -xc++ -o/dev/null -lc++ -shared
However I am using PowerShell, which has no notion of /dev/null:
PS C:\> cc -xc++ -o/dev/null -lc++ -shared
C:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../
x86_64-w64-mingw32/bin/ld.exe: cannot open output file /dev/null.exe: No such
file or directory
I tried using -o$null, but it just creates a file $null.exe. I also tried this:
PS C:\> cc -xc++ -o $null -lc++ -shared
cc.exe: fatal error: no input files
Is PowerShell able to handle this use case? Alternatively, it seems the purpose of the test is to just check if libc++ exists. Is another way available to do that?
It appears the issue is specific to GCC. If I get Clang, the same command
works with nul:
cc -xc++ -onul -lc++ -shared
but if I try the same thing with GCC, I get this:
C:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../
x86_64-w64-mingw32/bin/ld.exe: nul.exe: final close failed: file truncated
I have posted bug 97574.

Adding text files to binaries with objcopy, but objcopy complains about architecture

I've read about embedding text files (or any other resource for that matter) into binaries, and I'm doing it like so:
objcopy -I binary -O elf32-littlearm --binary-architecture arm myfile.txt myfile.txt.o
However, unlike in the tutorial, I get the following response:
ld: unknown architecture of input file `myfile.txt' is incompatible with arm output
The example uses i386 but this doesn't seem to be the issue either as I can't do it that way either.
Is there a way I can force objcopy to ignore the fact it's a text file and not a valid compatible binary so it just copies it byte-for-byte into my program?
For data only object file (no code), you can skip binary-architecture option.
So the following should work
objcopy -I binary -O elf32-littlearm myfile.txt myfile.txt.o to generate object file.

Why do I get an error with fopen when using matlab's mcc?

Setup:
Windows 7 Enterprise.
Matlab 7.10.0 (R2010a).
mcc compiler: Microsoft Visual C++ 2008 Express.
What's happening:
My project runs fine when running it through Matlab, but when trying to run the .exe through the command prompt after using mcc to compile, the command prompt generates an error.
The mcc command I issue is:
mcc -m -v STARTUP1.m -o EXE_REDUC
The error I receive in the command prompt is:
??? Error using ==> textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
I have a file called LoadXLS.m that loads and reads a .csv file using:
fid = fopen(file,'r');
temp_data = textscan(fid,...args...);
And then I process temp_data.
The csv file I'm trying to load is called spec.csv. It is located two directories down from where I have STARTUP1.m stored. The location of STARTUP1.m is also the place that the mcc generated files are stored to. I have used the pathtool to "Add with subfolders" this location, but am aware that those locations are not transferred to mbuild when compiling.
What I've Tried:
I have gone in and added print statements to print the value of fid to make sure it is valid. When I run it in Matlab, it has a valid value, however when I run in the command prompt it always returns an invalid value of -1.
I have removed all addpath() calls, I have tried adding the STARTUP1.m directory to the mcc ctf archive using:
mcc -m -v -a 'C:\Users\...path...\STARTUP1.m_location' STARTUP1.m -o EXE_REDUC;
However when I do this, I get a different error when running in the command prompt:
Cannot open CTF archive file
'C:\...path...\AppData\Local\Temp\mathworks_tmp_7532_28296'
or
'C:\...path...\AppData\Local\Temp\mathworks_tmp_7532_28296.zip'
??? Undefined function or variable 'matlabrc'.
To fix this, I've tried adding the pragma
%#function matlabrc
to the top of STARTUP1.m to try and enforce its inclusion, but had no success.
I also copied the spec.csv file to a new directory in the ctfroot and changed
fid = fopen(...)
to:
[tempFile, message] = fopen(fullfile(ctfroot, 'Added Config Files', ad.spec_file));
The message is:
message is: No such file or directory
Objective:
Rearranging file locations is a sufficient workaround while the exectuable only runs on my computer, however the idea is to take this standalone and distribute it to multiple people on many different computers. I would like to be able to have a top folder with a startup file and within this folder, have as many subfolders as the package requires. The startup file should be able to access all subfolders and files within them as necessary.
I read something about the exectuable actually running from a "secret location" on the machine here: http://matlab.wikia.com/wiki/FAQ
I would just like to be able to group one entire folder tree with all its files into a package containing the executable and be able to run it anywhere.
More info:
When I put the spec.csv file in the same directory as STARUTP1.m, it finds it fine using mcc without the -a 'path' option and using the following in the LoadXLS.m file:
[tempFile, message] = fopen(ad.spec_file,'r');
This project contains GUIs, generates PDFs, generates plots, and also creates a zip directory.
Thank you in advance.

Find unused resource files (.jsp, .xhtml, images) in Eclipse

I'm developing a large web application in Eclipse and some of the resources (I'm talking about files, NOT code) are getting deprecated, however, I don't know which are and I'm including them in my ending war file.
I know Eclipse recognizes file paths into its directory because I can access the link to an image or other page while I'm editing one of my xhtml pages (using Control). But is there a way to localize the unused resources in order to remove them?
Following these 3 steps would work for sites with a relatively finite number of dynamic pages:
Install your site on a filesystem mount'ed with atime (access time).
Try harvesting the whole site with wget.
Use find to see which files were not accessed recently.
Done.
As I know Eclipse doesn't have this (need this too).
I'm using grep in conjuction with bash scripting - shell script takes files in my resource folder, put filenames in list, greping throught source code for every record in the list and if grep find it it is removed.
At the end list is printed on console - just unused resources retain in the list.
UCDetector might be your best bet, specifically, the custom marker aspects of this tool.
In Eclipse I have not found a way. I have used the following shell command script.
Find .ftl template files which are NOT referenced in .java files
cd myfolder
find . -name "*.ftl" -printf "%f\n" |while read fname; do grep --include \*.java -rl "$fname" . > /dev/null || echo "${fname} not referenced" ; done;
or
Find all .ftl template files which are NOT referenced in .java, .ftl, .inc files
cd myfolder
find . -name "*.ftl" -printf "%f\n" |while read fname; do grep --include \*.java --include \*.ftl --include \*.inc -rl "$fname" . > /dev/null || echo "${fname} not referenced" ; done;
Note: on MacOSX you can use gfind instead of find in case -printf is not working.
Example output
productIndex2.ftl not referenced
showTestpage.ftl not referenced

Removing files with Build Phase?

Is it possible to remove a file using a build phase in xcode 4 based on if it is release or dev?
If so has anyone got an example?
I have tried :
if [ "${CONFIGURATION}" = "Debug" ]; then
find "$TARGET_BUILD_DIR" -name '*-live.*' -print0 | xargs -0 rm
fi
This prints CopyStringsFile
"build/Debug-iphonesimulator/Blue Sky.app/PortalText-live.strings" CDL/PortalText-live.strings
cd "/Users/internet/Desktop/iPhone Template/iPhonePortalTemplate/CDL.Labs"
setenv PATH "/Developer/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-copyStrings --validate --inputencoding utf-8 --outputencoding binary --outdir "/Users/internet/Desktop/iPhone Template/iPhonePortalTemplate/CDL.Labs/build/Debug-iphonesimulator/Blue Sky.app" -- CDL/PortalText-live.strings
But does actually remove the file from the bundle.
The only way I've ever had different files, is having a separate Target, and only include certain files in certain targets.
EDIT WITH AN EXAMPLE
Ok, I've done exactly the same in another project. We had a DefaultProperties.plist file, which was included in the target.
We then had 3 copies of this, NOT included in the target, ProdProperties.plist, TestProperties.plist, UatProperties.plist.
We built for environments on the command line, using xcodebuild, as it was built using an automated build server (Bamboo).
Prior to executing xcodebuild, we would run this:
cp -vf "./Properties/Environments/${environment}Properties.plist" ./Properties/shared/DefaultProperties.plist
touch Properties/shared/DefaultProperties.plist
with $(environment) being passed into the script.
You could do something like this with the RunScript phase in Xcode.