Всем привет. Пытаюсь компилировать следующую программу написанную на Си в NetBeans:
#include <stdio.h>
#include <math.h>
#define xmath -b+sqrt(D)/2*a
#define ymath -b-sqrt(D)/2*a
int main ()
{
double a, b, c, D, x1, x2;
printf ("Введите значение a:");
scanf ("%lf", &a);
if (a==0) {
printf ("a не может ровняться нулю!\n");
return 0;}
printf ("Введите значение b:");
scanf ("%lf", &b);
printf ("Введите значение c:");
scanf ("%lf", &c);
D=(b*b)-4*a*c;
if (D<0) {
printf ("D=%.3f D<0\n", D);
printf ("Нет корней!\n");
return 0;}
if (D==0) {
x1=xmath;
x2=ymath;
if (x1>0){
printf ("D=%.3f\n", D);
printf ("x1=%.3f\n", x1);
return 0;}
else {
printf ("D=%.3f\n", D);
printf ("x2=%.3f\n", x2);
return 0;}
}
if (D>0) {
x1=xmath;
x2=ymath;
printf ("D=%.3f\n", D);
printf ("x1=%.3f\n", x1);
printf ("x2=%.3f\n", x2);
return 0;}
}
Вылетает следующая ошибка:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Вход в каталог `/home/nadir/NetBeansProjects/CppApplication_1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppapplication_1
make[2]: Вход в каталог `/home/nadir/NetBeansProjects/CppApplication_1'
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/cppapplication_1 build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/nadir/NetBeansProjects/CppApplication_1/main.c:24: undefined reference to `sqrt'
/home/nadir/NetBeansProjects/CppApplication_1/main.c:25: undefined reference to `sqrt'
/home/nadir/NetBeansProjects/CppApplication_1/main.c:36: undefined reference to `sqrt'
/home/nadir/NetBeansProjects/CppApplication_1/main.c:37: undefined reference to `sqrt'
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
make[2]: *** [dist/Debug/GNU-Linux-x86/cppapplication_1] Ошибка 1
make[2]: Выход из каталога `/home/nadir/NetBeansProjects/CppApplication_1'
make[1]: *** [.build-conf] Ошибка 2
make[1]: Выход из каталога `/home/nadir/NetBeansProjects/CppApplication_1'
make: *** [.build-impl] Ошибка 2
СОБРАТЬ FAILED (значение выхода 2,, общее время: 173ms)
Собственно сам Makefile:
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_PLATFORM_${CONF} platform name (current configuration)
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
# build
build: .build-post
.build-pre:
# Add your pre 'build' code here...
.build-post: .build-impl
# Add your post 'build' code here...
# clean
clean: .clean-post
.clean-pre:
# Add your pre 'clean' code here...
.clean-post: .clean-impl
# Add your post 'clean' code here...
# clobber
clobber: .clobber-post
.clobber-pre:
# Add your pre 'clobber' code here...
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
# all
all: .all-post
.all-pre:
# Add your pre 'all' code here...
.all-post: .all-impl
# Add your post 'all' code here...
# build tests
build-tests: .build-tests-post
.build-tests-pre:
# Add your pre 'build-tests' code here...
.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...
# run tests
test: .test-post
.test-pre:
# Add your pre 'test' code here...
.test-post: .test-impl
# Add your post 'test' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
# include project make variables
include nbproject/Makefile-variables.mk
Доп инфа. Если написать в блокноте и попытаться скомпилировать следующим образом вылетала ошибка:
gcc -o ./main.c prog
Ошибка вылетала из-за того, что не подключалась библиотека <math.h>
Проблема решалась следующим образом:
gcc ./test.c -lm -o test
Но на данный момент мне нужно использовать именно NetBeans. Просьба другие варианты не предлагать.