我有这个简单的代码:
max = (int) sqrt (number);
Run Code Online (Sandbox Code Playgroud)
在标题中我有:
#include <math.h>
Run Code Online (Sandbox Code Playgroud)
但应用程序仍然表示未定义的引用sqrt.你觉得这里有什么问题吗?看起来一切都应该没问题.
这是一个概述我的问题的最小例子
test.c的:
#include <stdio.h>
#include <math.h>
main ()
{
fmod ( 3, 2 );
}
Run Code Online (Sandbox Code Playgroud)
这是我要编译的命令 test.c
gcc -lm test.c -o test
Run Code Online (Sandbox Code Playgroud)
这是我发出上述命令时得到的输出
/tmp/ccQmRk99.o: In function `main':
test.c:(.text+0x3e): undefined reference to `fmod'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
如果相反,我会使用相同的输出cc.我使用的是以下版本的gcc
gcc-4.6.real (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Run Code Online (Sandbox Code Playgroud)
我的程序无法编译的任何想法?
我的源代码有点问题.gcc对我说: 未定义引用`round'但我不知道为什么因为我正在使用stdio.h,stdlib.h,math.h ... :-(你可以帮我解决这个问题吗?
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <math.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define VERYBIG 200
int dir_size(const char* dirname)
{
int size = 0;
char path[VERYBIG];
struct stat tmp;
DIR* cat = opendir(dirname);
struct dirent* entry;
while ((entry = readdir(cat)))
{
if (!((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)))
{
path[0] = 0;
strcat(path, dirname);
strcat(path, "/");
strcat(path, entry->d_name);
if (lstat(path, &tmp) == -1)
perror("lstat");
if (S_ISDIR(tmp.st_mode))
{
size …Run Code Online (Sandbox Code Playgroud) 我已下载并编译:http://leenissen.dk/fann/wp/
用于编译的命令:
cmake -D CMAKE_INSTALL_PREFIX:PATH=/usr .
Run Code Online (Sandbox Code Playgroud)
安装:
sudo make && sudo make install
Run Code Online (Sandbox Code Playgroud)
然后我转到fann项目中的examples /目录并尝试通过运行编译示例:
make all
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
gcc -O3 xor_train.c -o xor_train -lfann -lm
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `sin'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `exp'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `cos'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `log'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `pow'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `sqrt'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `floor'
collect2: error: ld returned 1 exit status
make: *** [xor_train] Error 1
Run Code Online (Sandbox Code Playgroud)
更新:
阅读 math.h 的文档,似乎我所要做的就是包含 math.h,并使用包含的数学函数,例如 sqrt。问题是当我尝试在程序中使用 sqrt 时出现以下错误。我尝试了 math.sqrt,但这也不起作用。知道我做错了什么吗?
undefined reference to `sqrt'
Run Code Online (Sandbox Code Playgroud)
...
#include <stdio.h>
#include <math.h>
int main (int argc, char *argv[])
{
int a, b;
a = 1;
b = 5;
if (a < sqrt (b))
printf("1 < sqrt(5)");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我试图在C编程中找到平方根.但我得到的错误是对sqrt的未定义引用.我的代码是:
#include<stdio.h>
#include<math.h>
void main(void){
int x;
int y;
printf("Enter two number numbers");
scanf("%d", &x);
scanf("%d", &y);
int result;
result = ( x * x ) + ( y * y );
double finalresult = sqrt(result);
printf("%f\n", finalresult);
}
Run Code Online (Sandbox Code Playgroud) 我有一个在Windows中完美运行的代码但是当我尝试在linux中编译它时出现错误.我发现问题在于sin()功能.
如果我直接传递给它一个常数,它工作正常:
#include <stdio.h>
#include <math.h>
int main(void) {
float y = sin(1.57);
printf("sin(1.57) = %f", y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出1:
sin(1.57) = 1.000000
Run Code Online (Sandbox Code Playgroud)
但当我传递给它一个变量我得到一个错误:
#include <stdio.h>
#include <math.h>
int main(void) {
float x = 1.5;
float y = sin(x);
printf("sin(%f) = %f", x, y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出2:
/tmp/ccfFXUZS.o: In function `main':
source-bcfaa9ff162b:(.text+0x1a): undefined reference to `sin'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 我正在用linux中的opengl进行一些实验.我有以下功能,可以根据这些参数绘制一个圆圈.我已经包括在内了
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glut.h>
Run Code Online (Sandbox Code Playgroud)
但是当我编译时:
gcc fiver.c -o fiver -lglut
Run Code Online (Sandbox Code Playgroud)
我明白了:
/usr/bin/ld: /tmp/ccGdx4hW.o: undefined reference to symbol 'sin@@GLIBC_2.2.5'
/usr/bin/ld: note: 'sin@@GLIBC_2.2.5' is defined in DSO /lib64/libm.so.6 so try
adding it to the linker command line
/lib64/libm.so.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
功能如下:
void drawCircle (int xc, int yc, int rad) {
//
// draw a circle centered at (xc,yc) with radius rad
//
glBegin(GL_LINE_LOOP);
//
int angle;
for(angle …Run Code Online (Sandbox Code Playgroud) 我已将 math.h 包含在我的 c 文件中,但它保留了提示undefined reference to trunc和 undefined reference to ceil. 我什至没有在我的文件中使用 trunc 。谁能告诉我出了什么问题吗?
../NoteConverter.c: In function ‘main’:
../NoteConverter.c:154:9: warning: variable ‘position’ set but not used [-Wunused-but-set-variable]
Finished building: ../NoteConverter.c
Building target: NoteConverter
Invoking: GCC C Linker
gcc -o "NoteConverter" ./NoteConverter.o
../NoteConverter.c:21: error: undefined reference to 'sin'
collect2: error: ld returned 1 exit status
make: *** [NoteConverter] Error 1
Run Code Online (Sandbox Code Playgroud)
以下是代码
/**
* Frequency octave finder and play note
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#define DURATION 5
#define SAMPLERATE 48000
#define AMPLITUDE 1
//A*sin(2*pi*n*f/R)
double yCord(int n, double freq)
{
double y= sin(2*M_PI*freq*n/48000); …Run Code Online (Sandbox Code Playgroud)