I am writing a program using C, which, given two points, and a value x in between them, a function "Interp" will interpolate a corresponding value for y. I am receiving a message that says "undefined symbols for architecture", and I'm not sure how to fix it. Any help would be appreciated.
#include <stdio.h>
#include <math.h>
double Interp(double x_1, double y_1, double x_2, double y_2, double x) {
double k,y,b;
k = (y_2-y_1)/(x_2-x_1);
b = y_2-(k*x_2)
y = k*x+b;
return(y);
}
The result is a message saying "Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error linker command failed with exit code 1"
I don't know what this means so any guidance would be very helpful!
Related
I've been asked to write test programs on 4 functions in the card game dominion. I've written one (extremely simple) just to make sure I can get it to pass as I'm pretty new to testing. However, I continually get a syntax error at runtime that I cannot figure out.
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
int main() {
int r = 0, j = 0;
int adventurer = 8;
int greathall = 17;
r = getCost(adventurer);
assert(r == 6);
j = getCost(greathall);
assert(j == 3);
return 0;
}
When I compile it, I do get some warnings:
Undefined symbols for architecture x86_64:
"_getCost", referenced from:
_main in unittest1-7d7bf2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Which I'm not sure about either, but the base code that we are given from our instructor, as well as all of the other code from my classmates, has these warnings as well.
However, when running I get the following error:
./unittest1.c: line 8: syntax error near unexpected token `('
./unittest1.c: line 8: `int main() {'
I've tried rewriting it in a blank file thinking there was some invisible characters or something but I still get this error. Does anyone see something wrong in my code? Any help is appreciated.
**getCost is called in dominion_helpers
When I run this code in Xcode, I get build failed. I got the chunk from The Big Nerd Ranch Guide to Obj-C. I had to modify it a little (added the libraries stdlib.h and readline/readline.h) It says the build failed, but there are no errors that I can see. This question may look like a duplicate, and in a way it is, but even after seeing their solutions and trying them for myself, I still get the error.
#include <stdio.h>
#include <readline/readline.h>
#include <stdlib.h>
int main(int argc, const char * argv[])
{
printf("Who is cool? ");
const char *name = readline(NULL);
printf("%s is cool!\n\n", name);
return 0;
}
Undefined symbols for architecture x86_64: "_readline", referenced
from:
_main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see
invocation)
A similar problem is mentioned in this link. You have to link the libreadline.dylib file to your project in the build phase.
today I install mpi on mi mac 10.9 with home-brew mpicc works with a simlpe hello world program, but if I try somethings like this
#include <mpi.h>
#include <string.h>
#include <stdio.h>
#define max 1000
int main(int argv, char *argc[]){
int myrank,nProc,tag,j;
char buff [max];
MPI_Status status;
tag=0;
MPI_Init(&argv,&argc);
MPI_Comm_Rank(MPI_COMM_WORLD,&myrank);
MPI_Comm_Size(MPI_COMM_WORLD,&nProc);
if(myrank==0){
for(j =1 ; j<nProc;j++){
MPI_Recv(&buff,max,MPI_CHAR,j,tag,MPI_COMM_WORLD,&status);
printf("Il processo %d dice di chiamarsi %s\n",j,buff);
}
}
else{
switch (myrank){
case 1 :
MPI_Send("Franco",max,MPI_CHAR,j,tag,MPI_COMM_WORLD);
break;
case 2 :
MPI_Send("Mena",max,MPI_CHAR,j,tag,MPI_COMM_WORLD);
break;
case 3 :
MPI_Send("Nino",max,MPI_CHAR,j,tag,MPI_COMM_WORLD);
break;
}
}
printf("Ciao da %d \n",myrank);
MPI_Finalize();
return(0);
}
and i try compiling it whit the following row:
mpicc -o filename filename.c
it give me this warnings and not built .
nucciampi.c:15:3: warning: implicit declaration of function 'MPI_Comm_Rank' is
invalid in C99 [-Wimplicit-function-declaration]
MPI_Comm_Rank(MPI_COMM_WORLD,&myrank);
^
nucciampi.c:16:3: warning: implicit declaration of function 'MPI_Comm_Size' is
invalid in C99 [-Wimplicit-function-declaration]
MPI_Comm_Size(MPI_COMM_WORLD,&nProc);
^
2 warnings generated.
Undefined symbols for architecture x86_64:
"_MPI_Comm_Rank", referenced from:
_main in nucciampi-zsehoq.o
"_MPI_Comm_Size", referenced from:
_main in nucciampi-zsehoq.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
please help me to solve this issues!!!
MPI_Comm_Rank -> MPI_Comm_rank
MPI_Comm_Size -> MPI_Comm_size
There is a well-defined naming convention for all routines and constants in MPI and it is described in ยง2.2 of the MPI specification:
In C, all routines associated with a particular type of MPI object should be of the form MPI_Class_action_subset or, if no subset exists, of the form MPI_Class_action. In Fortran, all routines associated with a particular type of MPI object should be of the form MPI_CLASS_ACTION_SUBSET or, if no subset exists, of the form MPI_CLASS_ACTION. For C and Fortran we use the C++ terminology to define the Class. In C++, the routine is a method on Class and is named MPI::Class::Action_subset. If the routine is associated with a certain class, but does not make sense as an object method, it is a static member function of the class.
Note that unlike in Fortran, symbol names in C are case sensitive.
Yes, it's been asked before, but every answer I come up with on SO and elsewhere has to do with compiling C++ code in gcc instead of g++, or a issue of some kind with standard libraries. So far, nothing actually lining up right for me here.
So, I'm going through a basic crash course on C, and trying to compile an example used to illustrate linking to files that you create, rather than from the standard libraries. Here's the code:
math_functions.h
int sum (int x, int y);
float average (float x, float y, float z);
math_functions.c
int sum (int x, int y)
{
return (x + y);
}
float average (float x, float y, float z)
{
return (x + y + z) / 3;
}
and finally
test3.c
#include <stdio.h>
#include "math_functions.h"
main ()
{
int theSum = sum (8, 12);
float theAverage = average (16.9, 7.86, 3.4);
printf ("the sum is: %i ", theSum);
printf ("and the average is: %f \n", theAverage);
printf ("average casted to an int is: %i \n", (int)theAverage);
}
These are all in the same folder. When I open the Terminal, cd to the folder and run:
gcc test3.c -o test3
I get:
Undefined symbols for architecture x86_64:
"_average", referenced from:
_main in ccmf69Tt.o
"_sum", referenced from:
_main in ccxms0fF.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
This happens if I use gcc or g++ (which I shouldn't have to do, since this should all be C), and everything I've compiled before now works fine with the
#include <stdio.h>
at the top.
I can get it to compile and run fine by removing the
#include "math_functions.h"
from the test3.c file, putting the contents of math_functions.h before main() and the contents of math_functions.c after main(). And yes, that is copy and paste, so its definitely the same code.
So yeah, I can get my code to work, but it defeats the purpose of the exercise, in that I don't end up being able to use that code in any other C files without copying it and pasting it into the one file...
So I'm wondering, is there a way I can fix this, so I can include more that just the standard C, C++ and Objective-C libraries?
This happens through box the Terminal, manually typing out the gcc command, and through CodeRunner, which has the standard commands all tucked away into a button, so I can't stuff it.
I'm running Mountain Lion 10.8.4 (12E55) on a 2012 Mac Mini, using the Command Line Tools from Xcode 4.6.2 (installed them just a few hours ago, I haven't actually done much then standard use of the Mini till now)
I have all the same software installed on my MacBook Air, but haven't tested it to see if the same goes down yet.
Any pointers? If someone else has had this and worked it out somewhere here on SO, please point me at it, I have been looking for round an hour but like I said before, all the solutions that I've found so far end up being when there is C++ code or something weird with the standard libraries.
You just need to compile the maths_function. The linker is complaining it does not have the definitions contained in that module.
gcc test3.c math_functions.c -o test3
I am trying to do a simple strrev on a string and I keep getting this error when I compile it on my mac
Undefined symbols for architecture x86_64:
"_strrev", referenced from:
_main in cc1zSAum.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
My code is:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[]){
char str[] = "Hello world";
char * test;
test = strrev(str);
printf("%s",test);
return 0;
}
I tried playing around with the strrev line
but nothing is working
Any help would be appreciated
Thanks
There's no standard C function by that name. I did a little Googling and it looks like a few compilers and/or C library implementations have included such a function as a non-standard extension, but you can't expect any arbitrary library to have one.
Would be simple enough to write your own, though -- could be a one line loop body, even.